amdjs/backbone

Backbone-amd Load jQuery in Nodejs

FranckErnewein opened this issue · 4 comments

I like to use backbone on server (in nodejs) and on client for my applications.
And I like to use requirejs in both environment too.

So I use the same backbone on server side and on client side
I tried to use this one, but when I load Backbone-md with requirejs in nodejs, it forces to load jquery.
jquery is really embarassing in node cause it need window object etc.

It may just work if you point 'jquery' in the node case to a file that just does something like this:

define(function() {return function(){}});

That way the dependency is satisfied, but basically does nothing. This should address the issue, so closing, but feel free to continue discussion here.

Ok why not.
Actually it doesn't work for me because I'm using the same require.config on server and on client.
But nothing load jQuery on serveside (expect backbone-amd)

So choose to use classic version of backbone instead of this one, and everything is fine now.

So ... why this version ?
I mean, what are the advantages to use backbone-amd ?
because it doesn't need shim config maybe

You can call requirejs.config() multiple times and it tries to merge the calls up to about two levels deep. So what you could do after tha main requirejs.config() call:

// main config call
requirejs.config({});

// You would define isNode() just an example
if (isNode()) {
  requirejs.config({
    paths: {
      jquery: 'jquery-node'
  });
}

Where jquery-node is just the stub library.

This version of backbone exists so that it can be used in AMD systems without a shim config. Also, some people do want to use a jquery-like file with a DOM implementation in node, and that is possible with this file, since it correctly states the dependencies.

Oh ok nice !
I didn't know that it was possible to call require.config multiple times and override it.
Good idea

Thank you James