Skip to content

zomarg/loader.js

 
 

Repository files navigation

loader.js Build Status

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

We use testem for running our test suite.

You may run them with:

npm test

You can also launch testem development mode with:

npm run test:dev

License

loader.js is MIT Licensed.

About

minimal amd loader mostly stolen from wycats.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%