plovr
plovr copied to clipboard
Possible ES6 Module Support
Hello!
v20151216 of Closure Compiler (released after the version which officially started supporting ES6) understands ES6 modules. It also permits the intermingling of ES6 modules and "traditional" Closure JS files. This isn't, however, the case when the compiler is used through Plovr.
Plovr 5.0.0 comes bundled with Closure Compiler v20151216, but it doesn't seem to provide this ES6 module support. Plovr seems to have its own dependency resolution system which it uses to determine what files to feed to the built in closure compiler. And because this dependency resolution is seemingly based solely on goog.require/provide's, ES6 modules aren't "passed to the compiler". Is my understanding accurate? If yes, will Plovr eventually include ES6 module support?
Thanks!
bump. any update on this?
someone would need to volunteer to contribute it. I have no idea how much work this would take.
I just gave it a try and stopped at the following:
Need to include the file directly in your "inputs" field in config file of plovr. In my case:
"id": "formBuilder",
"inputs": [
"../js-formCommon/src/main/javascript/contexts/editions/objects/LabelEs6EditionContext.js",
"../js-formBuilder/src/main/plovrRequires/soyDeps.js",
"../js-formBuilder/src/main/javascript/Attach.js"
]
Otherwise it will not be visible in RAW mode, since like adityavohra7 said "Plovr seems to have its own dependency resolution system which it uses to determine what files to feed to the built in closure compiler."
Then create an es6 module encapsulated in goog.loadModule() (I followed my instinct to make it work in RAW mode and this snippet).
goog.loadModule(function (exports) {
"use strict";
goog.module("fusionmd.contexts.editions.objects.LabelEs6EditionContext");
exports = class LabelEs6EditionContext {
constructor() {
}
};
return exports;
});
To use the export you could invoke it like follow:
const LabelEs6EditionContext = goog.module.get("fusionmd.contexts.editions.objects.LabelEs6EditionContext");
It all worked fine in RAW mode but I gave up when I tried to compile.
[java] ../js-formBuilder/src/main/javascript/models/ToolboxDictionnary.js:20: ERROR - goog.module.get can not be called in global scope.
[java] const LabelEs6EditionContext = goog.module.get("fusionmd.contexts.editions.objects.LabelEs6EditionContext");