Skip to content

A CommonJS preprocessor that builds you CommonJS style app into code the browser can use.

Notifications You must be signed in to change notification settings

UmbraEngineering/common.js

Repository files navigation

CommonJS For The Browser

A CommonJS preprocessor that builds you CommonJS style app into code the browser can use.

Install

$ npm install common.js

Usage

Step 1: Write your JavaScript

foo.js
module.exports = function() {
	console.log('foo');
};
bar.js
var foo = require('foo');

exports.doTheThing = function() {
	foo();
};

Step 2: Build you code using commonjs-preprocessor

$ commonjs --src ./path/to/javascripts --dest ./path/to/js --client

Step 3: Include the modules into your app and use them

<script src="js/common.js"></script>
<script src="js/foo.js"></script>
<script src="js/bar.js"></script>
<script>
	var bar = require('bar');

	bar.doTheThing();
</script>

Lazy-loading extra scripts

require.load('/foo', '/bar', '/baz').then(function() {
	var foo = require('foo');
	var bar = require('bar');
	var baz = require('baz');

	foo.doStuffWith(bar.foo(), baz.foo());
});

About

A CommonJS preprocessor that builds you CommonJS style app into code the browser can use.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published