uncommon is a build tool for compiling a single browser compatible script from a CommonJS project
$ npm install uncommon
// use relative paths to load other modules in your projectvar foo = require'./foo';var bar = require'../lib/bar';// or reference an external dependency by namevar $ = require'jquery';// export the external interface as a modulemoduleexports =return barprocessdata;;moduleexportsfnx = foofnx;
Now create a
uncommon.config.json file at the root of your project to describe how it should be packaged:
Bundle the project into a single script using the
uncommon build command:
$ uncommon build path/to/project
Or host it on a local server that will rebuild the script as you make changes:
$ uncommon preview path/to/project --port 8888
uncommon will recursively find and package all of your project's required modules and create shims for any external dependencies. Your project is wrapped inside of a self-executing function along with a lightweight runtime (about 30 lines) for building and exporting your public interface. Your new package can be included like another script by adding
<script src="output_script.js"></script> to your html file.
uncommon is an alternative to the complicated and/or project specific tools used for packaging these scripts without their runtime dependencies.
uncommon you can write and organize your library or application as simple CommonJS modules and then compile them into a single script.
uncommoncan import dependencies from the global scope and expose them as modules; allowing your code to depend on shared libraries or legacy scripts that may already be loaded on the page. 'uncommon' can also export your module as a global symbol so legacy or inline scripts can use it without any loaders or modification. Projects configured for use with 'uncommon' are compatible with other CommonJS runtimes and package managers (such as npm).
uncommon requires your project to be defined using the CommonJS module 1.0 specification. As long as your code does not use any browser-only features or scripts it will be compatible with node.js as is, without any modification or build steps. External dependencies will be loaded in as node modules instead of being bootstraped by the uncommon runtime.
For packaging existing node modules for the browser, I recommend using browserify instead of
browserify has support for node specific features that
uncommon does not.
ender instead of
uncommon for building your project. For libraries and packages that are not meant to stand-alone,
uncommon can be used within packages or alongside
ender for building a drop-in ready script that is independent from npm.