Hello all,
Since XWiki 18.0.0RC1 it is possible to declare importmap from the properties of a maven module.
This allows JavaScript modules to easily be imported by other modules in the browser.
I naively started using this mechanism by declaring the importmap values in the importer of the module.
For instance, if a WebJar module needs Vue, I am adding the following property in its pom (in addition to adding the Vue WebJar in the runtime dependencies):
<xwiki.extension.javascript.modules.importmap>{
"vue": "org.webjars.npm:vue/dist/vue.runtime.esm-browser.prod.js"
}</xwiki.extension.javascript.modules.importmap>
This approach does not seem ok in practice because each module using Vue has to duplicate this importmap declaration.
What I propose is to move to an approach where the provider of the module declares the importmap.
In the case where the module is defined inside xwiki-platform, this is easy since we have control over the POM and can easily add the xwiki.extension.javascript.modules.importmap property pointing to the right JavaScript in the WebJar.
But things get more complex for webjars we do not control (e.g., the org.webjars.npm:vue WebJar used in the example above).
The best option I have in mind is to wrap the WebJar in a new module in xwiki-platform, only to add the xwiki.extension.javascript.modules.importmap.
For instance, for Vue we would:
- Add a new
xwiki-platform-webjar-vuemodule (inxwiki-platform-core/xwiki-platform-webjars/xwiki-platform-webjar-vue). - Add the
xwiki.extension.javascript.modules.importmapproperty with the right declaration. - Add
org.webjars.npm:vuein the runtime dependencies. - Replace all imports of
org.webjars.npm:vuewithorg.xwiki.platform:xwiki-platform-webjar-vue(but that wouldn’t cover contrib extensions unless they have a parent pom of 18.2.0+).
WDYT? Do you have an idea of another mechanism that would allow to declare the importmap for external WebJars in a less intrusive way?
Thanks!