Skip to content

Consider allowing map configs for loader plugin resource IDs #497

@jrburke

Description

@jrburke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy