jrburke/requirejs — pull request #375 by itay (2012-07-15 22:33:06+00:00)
Title: Add ability to dynamically add new shim files

Add the ability to add new shim files dynamically, such that dependencies can do it as well. This allows the following case:

main.js:

var someCondition = ...;
var deps = [];
if (someCondition) {
deps.push("path/to/mymodule.js");
}

require(deps, function(mymodule) {
if (mymodule) {
console.log(module.bar);
}
});

mymodule.js:

require.addShim({
"path/to/foo.js": {
deps: [],
exports: "foo"
},
"path/to/bar.js": {
deps: ["path/to/foo"],
exports: "bar"
}
});

define(["path/to/bar"], function(bar) {
return {
bar: bar
}
});

It's a bit of a contrived example, but my specific case happens when some inner dependency (which I don't know about in advance, so I can't include it in the call to `require.config`) needs some shimmed file, so I need to add it.

I'm sure this change would require more testing and comments/docs, I'm just curious what people think and whether this is acceptable at all.