Very simple and compact AMD loader intended for embedding directly into the page: minified size is under 1K bytes. Implements a subset of RequireJS API with a few extensions to make up for missing bits. Works on ES5-compliant browsers (hence IE9+ and Safari 6+).
define()
: three-argument form, i.e. named modules onlyrequire()
: both global and module-specific, two-argument formrequire.config()
: compatible with RequireJS, works as described here- Configuration options similar to RequireJS:
config
(extended functionality described below)paths
(extended functionality described below)urlArgs
- Special dependencies:
require
andmodule
- All modules must be named!
- No syntactic sugar such as simplified CommonJS wrapper, alternative forms of
require()
etc. - No
baseUrl
or module-relative paths: use extended form ofconfig.paths
(described below) - No RequireJS-style bundles: use external bundling (described below)
- Module object has only the
config()
method andid
property - No error handling: failed script loads do so silently
- No plugins (yet) or other bells and whistles of RequireJS
-
External bundling: eeMD recognizes script bundles loaded by external means (feature designed to support async script elements embedded into HTML content). Use
require.bundled()
instead ofrequire()
for those modules. The callback will be fired when all of the required modules define themselves: it doesn't matter whether they are loaded with one or multiple bundles. -
Module names are matched to paths via the
config.paths
dictionary using the "longest prefix" rule: if module"A/B/C"
that hasn't been yet defined is requested viarequire()
andconfig.paths
contains a pair"A/B": "/some/uri/prefix/"
then the module will be loaded from/some/uri/prefix/C.js
. If, on the other hand,config.paths
contained only a pair"A": "/some/uri/prefix/"
then the module would have been loaded from/some/uri/prefix/B/C.js
. A paths mapping of"": "/some/uri/prefix/"
is also valid and serves as an exact equivalent of RequireJS'sbaseUrl
setting. Note: make sure to always have a slash at the end of the path, eeMD doesn't waste bytes checking. -
Module configurations are found in the
config.config
dictionary using the "longest prefix" rule: if the configuration for module"A/B/C"
is not defined the the configuration for"A/B"
will be used, and so on; the same configuration dictionary can be passed to all modules viaconfig.config[""]
.