Skip to content Skip to sidebar Skip to footer

Backbone With Requirejs

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

Solution 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.

Solution 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
});

Post a Comment for "Backbone With Requirejs"