Closed elachys closed 5 years ago
I added the configuration parameter (closureJsModuleRoot
). This was simple enough.
As far as I could tell, the option works by removing a prefix from the name of all source files. Now this depends on how the source files are passed to closure compiler, ie. relative to which directory their names are.
Until now, all source files were passed relative to the target directory with the minified file(s). I'm not sure how you intend to use this option, but when I tried it, it did not seem to work well (source file names starting with ../..
). So I changed it and source file names are now passed to closure compiler relative to the given sourceDir
.
See the simple test I added how the option closureJsModuleRoot
can be used. The directory structure is as follows:
+ test
+ npm
+node_modules
+ to-array
+ index.js
- main.js
- package.json
Within main.js
, we import the module with
import { toArray } from "to-array";
The sourceDir
is set to test
and closureModuleResolution
is set to NODE
. This results in the source files being passed to closure compiler as main.js
and npm/node_modules/to-array/index.js
. By also setting closureJsModuleRoot
to npm
, this prefix is removed from the file name of the module. This results in node_modules/to-array/index.js
; to which the import statement to-array
can now be resolved.
You can try a snapshot of this version:
<plugin>
<groupId>com.github.blutorange</groupId>
<artifactId>closure-compiler-maven-plugin</artifactId>
<version>2.5.0-SNAPSHOT</version>
</plugin>
I'm not sure about your use case, but if it doesn't work, it would great if you could give a simple example / project setup that shows what you're trying to do.
Currently there is no way to pass the --js_module_root paramter to the closure compiler.
This should probably be done in closureConfig.java in the createCompilerOptions method (something like: options.setModuleRoots).