RE: Contribute requirejs.config.paths to ModuleManager

Svein-Erik Løken <[email protected]>
Newsgroups gmane.comp.java.tapestry.user
Message-ID <DB3PR08MB0283B61A3B6F2FAB9904871BD23A0@DB3PR08MB0283.eurprd08.prod.outlook.com>
I tried to fight it too, but had to capitulate. 

After some debugging my @Contribute(JavaScriptStackSource.class) was not set:

public class ModuleManagerImpl implements ModuleManager
{
private Resource resolveModuleNameToResource(String moduleName)
    {
        Resource resource = shimModuleNameToResource.get(moduleName);

        if (resource != null)
        {
            return resource;
        }

        // Tack on a fake extension; otherwise modules whose name includes a '.' get mangled
        // by Resource.withExtension().
        String baseName = String.format("/META-INF/modules/%s.EXT", moduleName);

        Resource baseResource = classpathRoot.forFile(baseName);

        for (String extension : extensions)
        {
            resource = baseResource.withExtension(extension);

            if (resource.exists())
            {
                return resource;
            }
        }

        // Return placeholder for null:
        return classpathRoot;
    }

My module is not listed in shimModuleNameToResource, and does not exist in /META-INF/modules/%s.EXT. The result is an empty classpathRoot.


I think I don't fully understand JavaScriptStack. I think a method is missing: Map<String, JavaScriptModuleConfiguration> getJavaScriptModules(). I would like to have a example of how to include a AMD/UMD module. What about support for CommonJS?




In the debugging process I found that @Contribute(ModuleManager.class) was the perfect choice for me.

    @Contribute(ModuleManager.class)
    public static void setupMyBaseModules(MappedConfiguration<String, Object> configuration, @Symbol(SymbolConstants.PRODUCTION_MODE) boolean productionMode) {
        String[] reactModules = {"react", "react-dom"};
        String ext = productionMode ? ".min.js" : ".js";
        for (String m : reactModules) {
            configuration.add(m, new JavaScriptModuleConfiguration(new ClasspathResource(String.format("META-INF/assets/js/%s%s", m, ext))));
        }
    }

I think I was fooled by:

The documentation for ModuleManager.class say:
"...This is primarily used to wrap non-AMD compliant libraries for use with RequireJS"

The internal variable Map<String, Resource> shimModuleNameToResource in ModuleManagerImpl. The shim prefix...

S-E




From: Chris Poulsen [via Apache Tapestry Mailing List Archives] [mailto:[email protected]] 
Sent: tirsdag 28. november 2017 08:34
To: Svein-Erik Løken <[email protected]>
Subject: Re: Contribute requirejs.config.paths to ModuleManager

Hi, 

It has been a while since I last fought the module system, but in some 
cases I've used a request filter to map between module and asset paths 
(triggering on known module paths and then returning permanent redirects to 
the actual asset urls in the filter) - This was necessary in order to get 
stuff like CK editor to load properly as a module and still allowing it to 
dynamically require its plugins IIRC. 

-- 
Chris 




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.