1

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 :)

2
  • Why do you need AMD? AMD in a Javascript app can add a lot of complexity, and it's not uncommon to overestimate one's need for a technical library. Commented Jan 25, 2013 at 7:57
  • 3
    It's also easy to neglect the need to organize/modularize your code early on, and then suddenly find that you have a mess of unmanageable spaghetti code. AMD makes it much easier to separate code into distinct modules, which is a plus when working with a framework like backbone (I think). Commented Jan 25, 2013 at 8:09

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

counting on your advise :)
can you help me understand what is meant by shimming of dependencies?
@MrinalPurohit You may try my answer, just insert a shim property in requirejs.config's properties argument.
@MrinalPurohit When some modules that you are loading are dependent on other modules, you achieve this through shims. Or when You need them to export an accessor parameter. Have a look at Requirejs docs on this: requirejs.org/docs/api.html#config-shim
4

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

4 Comments

yes you are correct. I studied that. Just want to know what the shim actually means. whats the meaning of shim configuration. Please shed some light.
shim is inspired by use.js, you may take a look at its source code to get some idea: github.com/tbranyen/use.js/blob/master/use.js
further, is datatables library AMD compatible? or i need to shim that dependency as well
Haven't used datatables library before, but it seems not to be AMD-compliant. Basically, you need shim any library that is not AMD-compliant when you need that available in define function's parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.