-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Spawned by the post from Gavin Jackson in this thread:
http://groups.google.com/group/requirejs/browse_thread/thread/28d8fa2aba128a59
One solution would be to map 'cs!whatever' to 'whatever' via an injection of requirejs config after a build, since after a build it would not make sense to dynamically load 'cs!whatever' if it was a built JS layer.
Not sure this is the right solution yet. It may require:
- a change to the optimizer to allow specifying "config injection", which would mean parsing for a requirejs.config() call.
- Update almond if this change goes in.
I did a quick hack (really needs cleanup) in the require-cs project to do this in makeModuleMap:
if (name) {
if (prefix) {
if (pluginModule && pluginModule.normalize) {
//Plugin is loaded, use its normalize method.
normalizedName = pluginModule.normalize(name, function (name) {
return normalize(name, parentName, applyMap);
});
} else {
normalizedName = normalize(name, parentName, applyMap);
}
//THIS IS THE NEW PART
if (config.map && config.map['*'] && config.map['*'][prefix + '!' + normalizedName]) {
normalizedName = config.map['*'][prefix + '!' + normalizedName];
prefix = undefined;
if (normalizedName.indexOf('!') === -1) {
url = context.nameToUrl(normalizedName);
}
}
} else {
//LEFT OUT FOR CLARITY
}
}
So it would be limited to full module IDs, not the partial mapping done for JS module map config, and only for '*', so normalized modules. I think this is OK though -- it only makes sense on normalized IDs.
One question would be if this is "map" config or if it should be something like "pluginMap" to indicate the special rules around full IDs only. That probably makes more sense, avoids confusion about non-* values not working.