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

Target directory not relative to source file directory #47

Closed Shabin closed 5 years ago

Shabin commented 5 years ago

I was using samaxes/minify-maven-plugin and I just upgraded to this plugin. After that I found a major mismatch in the ouptput directory location.

I have js files in multiple input folders

for eg: src\main\resources\META-INF\resources\js\f1\file1.js src\main\resources\META-INF\resources\js\f1\file2.js src\main\resources\META-INF\resources\js\f2\file3.js src\main\resources\META-INF\resources\scripts\file4.js

Using samaxes/minify-maven-plugin I used to configure like this

<webappSourceDir>${basedir}/src/main/resources/META-INF</webappSourceDir>
<webappTargetDir>${project.build.outputDirectory}/META-INF</webappTargetDir>
<jsSourceDir>resources</jsSourceDir>
<jsTargetDir>resources</jsTargetDir>
<jsSourceIncludes>
    <jsSourceInclude>js/**/*.js</jsSourceInclude>
        <jsSourceInclude>scripts/*.js</jsSourceInclude>
</jsSourceIncludes>

The minified files ouput for this used to be: src\main\resources\META-INF\resources\js\f1\file1.min.js src\main\resources\META-INF\resources\js\f1\file2.min.js src\main\resources\META-INF\resources\js\f2\file3.min.js src\main\resources\META-INF\resources\scripts\file4.min.js the target directory was same as the source directory.

But with the current plugin, for the configuration

<baseSourceDir>${basedir}/src/main/resources/META-INF</baseSourceDir>
<baseTargetDir>${project.build.outputDirectory}/META-INF</baseTargetDir>
<sourceDir>resources</sourceDir>
<targetDir>resources</targetDir>
<includes>
    <include>js/**/*.js</include>
    <include>scripts/*.js</include>
</includes>

the output is: src\main\resources\META-INF\resources\file1.min.js src\main\resources\META-INF\resources\file2.min.js src\main\resources\META-INF\resources\file3.min.js src\main\resources\META-INF\resources\file4.min.js

All output is coming to the targetDir location without considering the actual source path of the js file. How to achieve the older way of output.

blutorange commented 5 years ago

Your configuration looks good. It should output the files the way you expect. May be a bug, I'll take a look into what's going on.

blutorange commented 5 years ago

File paths are now preserved. The plugin option outputFilename now supports the variable #{path} and now defaults to

<configuration>
    <outputFilename>#{path}/#{basename}.min.#{extension}</outputFilename>
</configuration>

This should do what you need, see also the newly added test

You can try a snapshot of the next version:

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

Please report back if you notice anything not working. I'll release version 2.4.0 shortly.

blutorange commented 5 years ago

2.4.0 is available