A browser module loader that can load CommonJS/node and AMD modules. Built on top of RequireJS.
npm install cajonCajon is a JavaScript module loader
for the browser that can load CommonJS/node and AMD modules. It is built
on top of RequireJS.
You can use it to code modules for your project in CommonJS/node style, then
use the RequireJS Optimizer to
build all the modules into an AMD-compliant bundle. This allows you to
then use a small AMD API shim, like
almond, to get nicely optimized code
without needing a full runtime loader.
Why use this instead of RequireJS? Some possible reasons:
1) You cannot bring yourself to use a wrapper like this around your module
code:
``javascript`
define(function(require) {
/module code here /
});
2) You have a set of code already formatted in CommonJS/node style you
want to reuse.
Otherwise, you should be using RequireJS, or another AMD loader.
Note the Restrictions section below. You will likely gnash your
teeth in frustration if you do not heed them.
If you do not like this particular loader, but like the idea of a
dual AMD and CommonJS/node style module loader, then you may like
LinkedIn's Inject loader better.
Cajon is constructed with:
* RequireJS (needs 2.0.2 or later)
* An override to requirejs.load that fetches scripts via async
XHR requests then evals them, using the //@ sourceURL= to
specify the script names for script debuggers.
Cajon will only use the XHR+eval approach if the request is to the
same domain as the HTML document. If the script request is deemed to be on
another domain, it will just delegate to the default requirejs.load()
function, where it will load the script with a