diff --git a/src/main/java/org/primefaces/extensions/optimizerplugin/ResourcesOptimizerMojo.java b/src/main/java/org/primefaces/extensions/optimizerplugin/ResourcesOptimizerMojo.java index 411b016..fcf0d26 100755 --- a/src/main/java/org/primefaces/extensions/optimizerplugin/ResourcesOptimizerMojo.java +++ b/src/main/java/org/primefaces/extensions/optimizerplugin/ResourcesOptimizerMojo.java @@ -101,6 +101,12 @@ public class ResourcesOptimizerMojo extends AbstractMojo { @Parameter private boolean emitUseStrict; + /** + * Flag rewrites CommonJS modules so that modules can be concatenated together, by renaming all globals to avoid conflicting with other modules. + */ + @Parameter + private boolean processCommonJSModules; + /** * Suffix for compressed / merged files. */ @@ -243,7 +249,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { processJsFiles(file, subDirJsFiles, getSubDirAggregation(file, aggr, ResourcesScanner.JS_FILE_EXTENSION), getCompilationLevel(compilationLevel), getWarningLevel(warningLevel), - resolveSourceMap(null), null, getLanguageIn(languageIn), getLanguageOut(languageOut), emitUseStrict); + resolveSourceMap(null), null, getLanguageIn(languageIn), getLanguageOut(languageOut), emitUseStrict, processCommonJSModules); } } } @@ -260,7 +266,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // handle JavaScript files processJsFiles(dir, scanner.getJsFiles(), aggr, getCompilationLevel(compilationLevel), getWarningLevel(warningLevel), resolveSourceMap(null), suffix, - getLanguageIn(languageIn), getLanguageOut(languageOut), emitUseStrict); + getLanguageIn(languageIn), getLanguageOut(languageOut), emitUseStrict, processCommonJSModules); } } } @@ -337,7 +343,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { processJsFiles(file, subDirJsFiles, getSubDirAggregation(file, aggr, ResourcesScanner.JS_FILE_EXTENSION), resolveCompilationLevel(rs), resolveWarningLevel(rs), - resolveSourceMap(rs), null, resolveLanguageIn(rs), resolveLanguageOut(rs), emitUseStrict); + resolveSourceMap(rs), null, resolveLanguageIn(rs), resolveLanguageOut(rs), emitUseStrict, processCommonJSModules); } } } @@ -354,7 +360,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // handle JavaScript files processJsFiles(dir, scanner.getJsFiles(), aggr, resolveCompilationLevel(rs), resolveWarningLevel(rs), resolveSourceMap(rs), suffix, - resolveLanguageIn(rs), resolveLanguageOut(rs), emitUseStrict); + resolveLanguageIn(rs), resolveLanguageOut(rs), emitUseStrict, processCommonJSModules); } } } @@ -391,11 +397,11 @@ private void processCssFiles(final File inputDir, final Set cssFiles, fina private void processJsFiles(final File inputDir, final Set jsFiles, final Aggregation aggr, final CompilationLevel compilationLevel, final WarningLevel warningLevel, final SourceMap sourceMap, final String suffix, - final LanguageMode languageIn, final LanguageMode languageOut, boolean emitUseStrict) throws MojoExecutionException { + final LanguageMode languageIn, final LanguageMode languageOut, boolean emitUseStrict, boolean processCommonJSModules) throws MojoExecutionException { resFound = true; final ResourcesSetAdapter rsa = new ResourcesSetJsAdapter( inputDir, jsFiles, aggr, compilationLevel, warningLevel, sourceMap, encoding, - failOnWarning, suffix, languageIn, languageOut, emitUseStrict); + failOnWarning, suffix, languageIn, languageOut, emitUseStrict, processCommonJSModules); final ClosureCompilerOptimizer closureOptimizer = new ClosureCompilerOptimizer(getLog()); closureOptimizer.optimize(rsa); @@ -664,4 +670,4 @@ private double round(final double value, final int places) { return roundedValue; } -} +} \ No newline at end of file diff --git a/src/main/java/org/primefaces/extensions/optimizerplugin/optimizer/ClosureCompilerOptimizer.java b/src/main/java/org/primefaces/extensions/optimizerplugin/optimizer/ClosureCompilerOptimizer.java index 1ccc40f..7a9cfd0 100755 --- a/src/main/java/org/primefaces/extensions/optimizerplugin/optimizer/ClosureCompilerOptimizer.java +++ b/src/main/java/org/primefaces/extensions/optimizerplugin/optimizer/ClosureCompilerOptimizer.java @@ -83,6 +83,8 @@ public void optimize(final ResourcesSetAdapter rsAdapter) throws MojoExecutionEx options.setEmitUseStrict(rsa.isEmitUseStrict()); options.setEnvironment(CompilerOptions.Environment.BROWSER); + options.setProcessCommonJSModules(rsa.isProcessCommonJSModules()); + try { final Charset cset = Charset.forName(rsa.getEncoding()); diff --git a/src/main/java/org/primefaces/extensions/optimizerplugin/util/ResourcesSetJsAdapter.java b/src/main/java/org/primefaces/extensions/optimizerplugin/util/ResourcesSetJsAdapter.java index c7e143a..6238956 100755 --- a/src/main/java/org/primefaces/extensions/optimizerplugin/util/ResourcesSetJsAdapter.java +++ b/src/main/java/org/primefaces/extensions/optimizerplugin/util/ResourcesSetJsAdapter.java @@ -45,10 +45,11 @@ public class ResourcesSetJsAdapter extends ResourcesSetAdapter { private final LanguageMode languageOut; private final boolean emitUseStrict; + private boolean processCommonJSModules; public ResourcesSetJsAdapter(File inputDir, Set files, Aggregation aggregation, CompilationLevel compilationLevel, WarningLevel warningLevel, SourceMap sourceMap, String encoding, boolean failOnWarning, - String suffix, LanguageMode languageIn, LanguageMode languageOut, boolean emitUseStrict) { + String suffix, LanguageMode languageIn, LanguageMode languageOut, boolean emitUseStrict, boolean processCommonJSModules) { super(inputDir, files, aggregation, encoding, failOnWarning, suffix); this.compilationLevel = compilationLevel; this.warningLevel = warningLevel; @@ -56,6 +57,7 @@ public ResourcesSetJsAdapter(File inputDir, Set files, Aggregation aggrega this.languageIn = languageIn; this.languageOut = languageOut; this.emitUseStrict = emitUseStrict; + this.processCommonJSModules = processCommonJSModules; } public CompilationLevel getCompilationLevel() { @@ -81,4 +83,8 @@ public LanguageMode getLanguageOut() { public boolean isEmitUseStrict() { return emitUseStrict; } -} + + public boolean isProcessCommonJSModules() { + return processCommonJSModules; + } +} \ No newline at end of file