You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider allowing map configs for loader plugin resource IDs #497
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){returnnormalize(name,parentName,applyMap);});}else{normalizedName=normalize(name,parentName,applyMap);}//THIS IS THE NEW PARTif(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.
pluginMap seems better. Putting this in the 2.1.2 bucket as 2.1.1 is almost out the door. This may get pushed to a 2.2.0 if further implementation investigation makes this awkward. In particular, doing config auto-injection.
Maybe this is just mainConfigFile -- using that to know where to inject.
Firstly, am I correct in assuming this applies to all plugins, not just cs!? So the same would happen for say, require-css!css-file being path mapped to a layer? If so, perhaps a solution could double up with paths config using the following rule:
When reading paths configs, extract out any paths configs containing a '!' indicating that they are plugin path maps and not standard paths configs. This is ok since paths maps with a '!' make no sense otherwise.
When processing a require first check if the moduleId matches one of these 'plugin maps' exactly and if so apply the mapping.
All other path rules apply normally after this.
That's the best I can come up with. I have a custom script populating all the build paths to the layers (as you previously suggested). This script would work directly with such a method above as it wouldn't need to distinguish between plugins and normal paths separating the configs.
@guybedford yes it would be generic for all plugins. I'm favoring "pluginMap" for the config value and it would work like "map", except it would work on full plugin IDs, not partial module ID prefixes as "map" does today.
The other part of this is that the optimizer would inject this config directly into probably the mainConfigFile's config section. This last part is what causes this bug to be pushed forward to a later release.
@jrburke the pluginMap support sounds great - it is much needed.
I'm still not entirely sure though why this needs a configuration injection. If a layer is loaded and defines an absolute moduleId, 'cs!my/module', then surely a subsequent request to 'cs!my/module' will load directly from the defined version without needing access to the plugin?
@jrburke I think I finally understand what you mean - are you indicating that the injection of this new configuration property would happen into the main config file?
So if this was main.js, then the config at the top of main.js would be ammended with this new layer map property?
One thing to bear in mind is also allowing this file to be created itself, so that in my case, where I'm running a multi-page app where HTML pages are dynamically generated, the app can load this created JSON file and then use this to do the injection itself for all pages. This would cover #327.
Yes, the config block found via mainConfigFile would be modified. The first pass of this in the optimizer will target the mainConfigFile. Once that gets sorted out, maybe we can do another pass that allows mainConfigFile to just be a JSON file.
Thanks, I'm happy to help out along these lines once the initial code is up. It's specifically getting the config injection data within in the NodeJS optimization that I am targeting here. When running an optimization as part of a larger build / app, getting this info is quite important for page generation when the framework handles the injection itself.
Having finally sorted out the build, this is now the final roadblock (I hope) for my production environment.
So if there's anything I can do to help, just let me know - happy to get involved.
Note - specifically the issue is ensuring that requires to plugin resource module IDs can load from built layers through a pluginMap config or paths variation.
Going to see about bundling this with #638, and given the config rewriting, best to do in a .0 release. I do hope that 2.2.0 is the next release after 2.1.5 though. Based on the amd discussion list, a layers property might make sense. Although for #638, making sure map configs for loader plugin resource IDs work would be good. Since loader plugin IDs, they would be exact match hits since the ID is opaque to the loader.
Activity
jrburke commentedon Oct 14, 2012
pluginMap seems better. Putting this in the 2.1.2 bucket as 2.1.1 is almost out the door. This may get pushed to a 2.2.0 if further implementation investigation makes this awkward. In particular, doing config auto-injection.
Maybe this is just mainConfigFile -- using that to know where to inject.
jrburke commentedon Nov 20, 2012
The config auto injection is the big blocker for this. Running out of time for 2.1.2, pushing forward, may still end up in 2.2.0.
guybedford commentedon Nov 21, 2012
Firstly, am I correct in assuming this applies to all plugins, not just
cs!? So the same would happen for say,require-css!css-filebeing path mapped to a layer? If so, perhaps a solution could double up with paths config using the following rule:That's the best I can come up with. I have a custom script populating all the build paths to the layers (as you previously suggested). This script would work directly with such a method above as it wouldn't need to distinguish between plugins and normal paths separating the configs.
jrburke commentedon Nov 30, 2012
@guybedford yes it would be generic for all plugins. I'm favoring "pluginMap" for the config value and it would work like "map", except it would work on full plugin IDs, not partial module ID prefixes as "map" does today.
The other part of this is that the optimizer would inject this config directly into probably the mainConfigFile's config section. This last part is what causes this bug to be pushed forward to a later release.
guybedford commentedon Dec 1, 2012
@jrburke the
pluginMapsupport sounds great - it is much needed.I'm still not entirely sure though why this needs a configuration injection. If a layer is loaded and defines an absolute moduleId, 'cs!my/module', then surely a subsequent request to 'cs!my/module' will load directly from the defined version without needing access to the plugin?
jrburke commentedon Dec 3, 2012
The problem is initial load. If all is built, there is no need to load the plugin, the built .js file is the thing that should get loaded.
jrburke commentedon Dec 3, 2012
As @guybedford mentions in requirejs/r.js#327, this same sort of map would be useful for non-plugin resources.
So, a way to inject a paths config that points loading of certain modules IDs to the same built file.
Since that requires the same requirejs config modification as this ticket, I'll track it in this ticket for now.
guybedford commentedon Dec 7, 2012
@jrburke I think I finally understand what you mean - are you indicating that the injection of this new configuration property would happen into the main config file?
So if this was
main.js, then the config at the top ofmain.jswould be ammended with this new layer map property?One thing to bear in mind is also allowing this file to be created itself, so that in my case, where I'm running a multi-page app where HTML pages are dynamically generated, the app can load this created JSON file and then use this to do the injection itself for all pages. This would cover #327.
jrburke commentedon Dec 10, 2012
Yes, the config block found via mainConfigFile would be modified. The first pass of this in the optimizer will target the mainConfigFile. Once that gets sorted out, maybe we can do another pass that allows mainConfigFile to just be a JSON file.
guybedford commentedon Dec 12, 2012
Thanks, I'm happy to help out along these lines once the initial code is up. It's specifically getting the config injection data within in the NodeJS optimization that I am targeting here. When running an optimization as part of a larger build / app, getting this info is quite important for page generation when the framework handles the injection itself.
jrburke commentedon Jan 18, 2013
This is partly done, in that r.js can find a config, then inject a modified config in a file. Tests here.
However, I am waiting on the result of the "precise ID config" amd-implement discussion to do the final config stamping work.
So pushing the rest of this until 2.1.4.
guybedford commentedon Jan 26, 2013
Having finally sorted out the build, this is now the final roadblock (I hope) for my production environment.
So if there's anything I can do to help, just let me know - happy to get involved.
Note - specifically the issue is ensuring that requires to plugin resource module IDs can load from built layers through a pluginMap config or paths variation.
guybedford commentedon Jan 26, 2013
Although this isn't too critical, because in most scenarios another resource hits the layer first stopping this from being a major issue just yet.
jrburke commentedon Feb 19, 2013
Going to see about bundling this with #638, and given the config rewriting, best to do in a .0 release. I do hope that 2.2.0 is the next release after 2.1.5 though. Based on the amd discussion list, a layers property might make sense. Although for #638, making sure map configs for loader plugin resource IDs work would be good. Since loader plugin IDs, they would be exact match hits since the ID is opaque to the loader.
jrburke commentedon Dec 2, 2013
Consider for 2.1.10: has come up in case for dojo i18n bundling, where it would want to load a layer like this:
with a module doing this:
Ideally this sort of config would work:
See if it makes sense to just put this in 2.1.10 instead of 2.2.
jrburke commentedon Jan 6, 2014
Just committed support for a "bundles" config, will be part of 2.1.10:
Keys and values are full module IDs, not module ID prefixes, and not path segments. API doc will be updated once 2.1.10 is pushed.
guybedford commentedon Jan 6, 2014
Nice!