简体   繁体   English

带requirejs的主干

[英]backbone with requirejs

I am building a complex web app and trying to use requirejs with backbone. 我正在构建一个复杂的Web应用程序,并试图将requirejs与主干一起使用。 I found out that backbonejs is a non AMD framework which restricts me to use requirejs out of the box. 我发现bonesjs是非AMD框架,这限制了我开箱即用地使用requirejs。

I researched on internet and found that there are patches available to make backbone AMD compliant. 我在互联网上进行了研究,发现有一些补丁可以使主干AMD兼容。

Please guide if patching this way is a no-issue setup. 请指导是否以这种方式打补丁没有问题。 Will i run into any issues during the app development due to patching of core file in backbonejs? 我的应用开发过程中是否会由于中骨干js的核心文件补丁而遇到任何问题?

I apologise if its a stupid question :) 如果这是一个愚蠢的问题,我表示歉意:)

Nope, it's not a stupid question. 不,这不是一个愚蠢的问题。 We actually have done this and is working fine for us, so far :) 实际上,我们已经做到了这一点,并且到目前为止对我们来说还不错:)

You can follow this guide on how to do it: http://kilon.org/blog/2012/08/build-backbone-apps-using-requirejs/ 您可以按照以下指南操作: http//kilon.org/blog/2012/08/build-backbone-apps-using-requirejs/

Don't forget to read the chapter on unit testing it with Jasmine. 不要忘记阅读有关使用Jasmine进行单元测试的章节。 Pretty nice combination all together. 很好的组合在一起。

Before Require.js 2.0, you have to patch Backbone to be AMD compliant. 在Require.js 2.0之前,您必须修补Backbone以使其兼容AMD。 You can find some AMD-compliant forks of Backbone on github(eg amdjs ). 您可以在github上找到一些与AMD兼容的Backbone分支(例如amdjs )。 Fortunately, Require.js 2.0+ added support for loading non-AMD compatible scripts by using the Shim configuration. 幸运的是,Require.js 2.0+添加了对使用Shim配置加载非AMD兼容脚本的支持。 Example: 例:

requirejs.config({
    shim: {
      "backbone": {
          deps: ["underscore", "jquery"],
          exports: "Backbone"
      }
    },

    paths: {
    // as usual
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM