loader.js
Minimal AMD loader mostly stolen from @wycats.
No Conflict
To prevent the loader from overriding require
, define
, or requirejs
you can instruct the loader
to use no conflict mode by providing it an alternative name for the various globals that are normally used.
Example:
loader.noConflict({
define: 'newDefine',
require: 'newRequire'
});
Note: To be able to take advantage of alternate define
method name, you will also need to ensure that your
build tooling generates using the alternate. An example of this is done in the emberjs-build
project in the babel-enifed-module-formatter plugin.
wrapModules
It is possible to hook loader to augment or transform the loaded code. wrapModules
is an optional method on the loader that is called as each module is originally loaded. wrapModules
must be a function of the form wrapModules(name, callback)
. The callback
is the original AMD callback. The return value of wrapModules
is then used in subsequent requests for name
This functionality is useful for instrumenting code, for instance in code coverage libraries.
loader.wrapModules = function(name, callback) {
if (shouldTransform(name) {
return myTransformer(name, callback);
}
}
return callback;
};
Tests
To run the test you'll need to have
testem installed. Install it with npm install -g testem
.
(You'll also have to install the bower components, which you can do by running
bower install
)
You may run them with:
testem ci
You can also launch testem development mode with:
testem
License
loader.js is MIT Licensed.