backbone with requirejs

安稳与你 提交于 2019-12-24 14:03:55

问题


I am building a complex web app and trying to use requirejs with backbone. I found out that backbonejs is a non AMD framework which restricts me to use requirejs out of the box.

I researched on internet and found that there are patches available to make backbone AMD compliant.

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?

I apologise if its a stupid question :)


回答1:


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/

Don't forget to read the chapter on unit testing it with Jasmine. Pretty nice combination all together.




回答2:


Before Require.js 2.0, you have to patch Backbone to be AMD compliant. You can find some AMD-compliant forks of Backbone on github(e.g. amdjs). Fortunately, Require.js 2.0+ added support for loading non-AMD compatible scripts by using the Shim configuration. Example:

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

    paths: {
    // as usual
});


来源:https://stackoverflow.com/questions/14517548/backbone-with-requirejs

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