I have an existing site that uses requirejs for everything from loading libraries such as jQuery and Backbone to defining Backbone views, models etc. I'm trying to get this to render on the server-side with node.js and therefore need an entirely separate context stack for each request.
Requirejs's multiversion support has almost what I need. It allows for the declaring of a special context for future loads. var context1 = require.config({context: "abc123"}); This then allows: context1(['item'], function(item){}); where 'item' will be loaded separately even if it has been loaded already. Unfortunately I need the required item to also have the ability to require and define items isolated into that context stack.
Requirejs almost has this feature set with the internal takeGlobalQueue function. Unfortunately this function expects to grab all of the items defined since the most recent call, and therefore could grab items defined on a different context stack.
What I need is a way to have requirejs give me a truely separate instance of define/require which maintain that separation through future calls.
I don't want to rewrite my entire site to not use requirejs and/or to need some plugin for all my requirejs calls. Should I be hacking on the r.js source for this? Is this something that goes against the AMD specification?
Update 1: Say on nodejs I create a window context using domino/jsdom. I then attach a copy of jQuery/zepto and Backbone to that window such that Backbone.View.make creates an element in that window. I can then load my actual application stack which then inherits off THAT copy of backone such that everything "just works" as if it were in the browser. No need to hack the jquery/backbone source. But I need a separate copy of Backbone pointing to a separate window for a different simultaneous request, and that means a separate context stack of my views/models etc.