Dependency Management Got Awesome
CommonJS and AMD Compliant dependency loader for modern web apps
require
0.4.x
OLD: This is an old version of documentation. You probably want the most recent version of this
document, from the sidebar on the right.
require('moduleName');
The default interface for CommonJS, require()
takes a single parameter as a string. Rarely (if ever) will require be used from the global namespace, but instead from within the context of a module. If the module has not been defined by the time require()
is called, an Exception is thrown.
AMD Interface
require(['one', 'two', 'three'], function (one, two, three) {});
AMD specifies an alternate syntax for require, which takes an array of dependencies, followed by a callback function which receives the list of paramters in the order they were listed. Key builtins of require
, module
, and exports
won’t resolve to modules, but instead will resolve to their matching module counterparts. It’s behavior is very similar in design to require.ensure.