【问题标题】:Using require.js with Twitter Boostrap API and backbone将 requirejs 与 Twitter Bootstrap API 和主干一起使用
【发布时间】:2012-10-17 11:39:48
【问题描述】:

关于这个条目Loading Backbone and Underscore using RequireJS,我很清楚如何配置Backbone-特定脚本和JQuery

但是我该怎么做:

  • 配置Twitter bootstrap.js?
  • json2.js 呢?

谢谢!

【问题讨论】:

    标签: javascript jquery backbone.js twitter-bootstrap requirejs


    【解决方案1】:

    除了了解路径配置选项之外,您还应该查看 shim 配置选项 http://requirejs.org/docs/api.html#config-shim

    许多插件还没有支持 AMD,因此您有两种选择。要么将其配置为 shim(适用于大多数插件),要么编写自己的适配器,例如 https://github.com/amdjs

    简单示例:

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

    对于像 json2 这样没有依赖项并且仅在浏览器没有本机实现时才激活的东西,您可以简单地将其列为主应用程序的依赖项,而无需包装器/填充程序。

    【讨论】:

      猜你喜欢
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      相关资源
      最近更新 更多