This plugin for RequireJS will give support to load javascript files that doesn't have support to AMD pattern, but declare some global var.
This plugin support RequireJS Optimizer.
Some libs that this plugin will help you:
- Underscore: http://documentcloud.github.com/underscore/
- Backbone: http://documentcloud.github.com/backbone/
- Zepto: http://zeptojs.com/
It's very simple to configure:
- wrapper
- globals
- deps
In globals you must declare your include path as key and the generated global as value.
Exemple for underscore
:
wrapper: {
globals: {
'lib/underscore': '_'
}
}
Or you can use a function to get the return like:
wrapper: {
globals: {
'lib/underscore': function() { return window._.noConflict(); }
}
}
Some libs can have dependencies, like Backbone
, so this feature is to solve this problem very simple.
Because you are working with libs that don't support AMD pattern, you will need to setup their depences in the
config file.
Exemple for Backbone
:
wrapper: {
globals: {
'lib/underscore': '_',
'lib/backbone': 'Backbone'
},
deps: {
'lib/backbone': ['lib/underscore']
}
}
It's very simple, you just need to require your target with plugin wrap, example:
define(['wrap!underscore'], function( _ ) {
console.debug(_); // returns underscore content
});
Check RequireJS documentation for a basic reference and use other plugins as reference. RequireJS official plugins are a good source for learning.
Also be sure to check RequireJS Wiki.
Gabriel Reitz Giannattasio (Gartz)
All the plugins are released under the MIT license.