2

Regarding this entry Loading Backbone and Underscore using RequireJS it is quite clear to me how do I configure Backbone-specific scripts and JQuery.

But how do I:

  • configure Twitter bootstrap.js?
  • what about json2.js?

Thanks!

Community
  • 1
  • 1
lexeme
  • 2,915
  • 10
  • 60
  • 125

1 Answers1

6

In addition to what you learned about the path config option, you should also review the shim config option http://requirejs.org/docs/api.html#config-shim.

Many plugins are not AMD ready so you have two options. Either configure it as a shim (suitable for most plugins), or write your own adapters like the efforts at https://github.com/amdjs

Simple example:

require.config({
    shim: {
        'bootstrap': ['jquery'], // no exports
        'underscore': { exports: '_' }, // no dependencies
        'backbone.layoutmanager': {
            deps: ['backbone']
            exports: 'Backbone.LayoutManager'
        } // a mix of exports and dependencies
     }
});

For something like json2 which has no dependencies and only activates if the browser has no native implementation, you can simply list it as a dependency of your main application's require without a wrapper / shim.

johlrich
  • 1,771
  • 1
  • 12
  • 11