Dependency Management Got Awesome
CommonJS and AMD Compliant dependency loader for modern web apps
AMD and Inject
0.7.x
Inject is an AMD compatible framework and supports the following specifications:
- basic
- anon
- funcString
- namedWrapped
- require
- plugins
This means AMD ready modules can be used straight away with Inject, just like any other system. To define an AMD module, you should use the define function
define('moduleName', [dependencies], function(dependencyOne, dependencyTwo) {});
The define function takes three parts
- an optional module name (if not provided, it will be inferred from the file running)
- an optional array of dependencies
- a factory function or object. If a function, it will be ran once all dependencies are available. If an object, it will be assigned to the module’s export once dependencies have resolved.
Full details on writing AMD compliant modules are available in the AMD Wiki
AMD Plugins
It’s possible to enable AMD plugin support using the following config:
Inject.useAMDPlugins()
This allows you to use standard AMD Loader Plugins, with the added benefit of localStorage caching for the plugin code. By default, all AMD plugins loaded with Inject are treated as dynamic, and are rerequested on each occurance. This is due to loader plugins not having their own local resource cache.