Using require.js with Twitter Boostrap API and backbone

我与影子孤独终老i 提交于 2019-12-24 02:43:25

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/12933466/using-require-js-with-twitter-boostrap-api-and-backbone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!