blutorange / closure-compiler-maven-plugin

Combine and minimize JavaScript with Closure Compiler.
http://blutorange.github.com/closure-compiler-maven-plugin
Apache License 2.0
52 stars 6 forks source link

Compilation without renaming? #56

Closed floverfelt closed 3 years ago

floverfelt commented 3 years ago

Is there a way to use this plugin where the minified files replace the originals? That is - after minification the source file is removed and only the minified file remains with the same name?

I'm attempting to execute a multi-module build of wars which are combined into a single war. Sample from the pom: `

UTF-8
          <baseSourceDir>${project.build.directory}/war/work</baseSourceDir>
          <baseTargetDir>${project.build.directory}/war/work</baseTargetDir>
          <sourceDir>${project.groupId}</sourceDir>
          <targetDir>${project.groupId}</targetDir>
          <outputFilename>#{path}/#{basename}.#{extension}</outputFilename>
          <includes>**/*.js</includes>
          <excludes>**/*.min.js, **/backup/*.js</excludes>
          <skipMerge>true</skipMerge>
        </configuration>

`

However, this errors due to: org.apache.maven.plugin.MojoFailureException: The source file [fileName.js] has the same name as the output file [fileName.js].

Is there a way to add support for this by skipping this assertion: https://github.com/blutorange/closure-compiler-maven-plugin/blob/master/src/main/java/com/github/blutorange/maven/plugin/closurecompiler/plugin/ProcessFilesTask.java#L131

Or point me in the right direction of how you can execute the plugin on files and replace the existing. Thanks!

blutorange commented 3 years ago

Hmm, right now that is a safety check to ensure people do not override their source files. I could add an additional flag to allow for this.

I'm assuming you cannot just use a different output directory?

floverfelt commented 3 years ago

@blutorange no, we're currently dependent on a third party war to actually serve our JS files. That app has strict requirements on the file names matching a certain naming convention and existing in a certain directory. We cannot append a .min or anything or else the JS file serving mechanism breaks. It's a real pain.

I'm trying to modify all JS fetched from dependent wars in the /war/work directory of the maven-war-plugin. Thus, it's not really modifying the true source files but rather the files we are caching and assembling into the final war.

An additional flag that defaults to FALSE (do not skip check) and a warning in the docs would be good.

blutorange commented 3 years ago

I added the flag allowReplacingInputFiles, see the test case for an example. You can try a snapshot (might take a day until it's available via maven central):

    <plugin>
      <groupId>com.github.blutorange</groupId>
      <artifactId>closure-compiler-maven-plugin</artifactId>
      <version>2.19.0-SNAPSHOT</version>
    </plugin>

I'll close this issue for now and release version 2.19 soon. If something should not be working, just report back.

floverfelt commented 3 years ago

Thank you! This plugin is incredibly helpful.