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

closureCreateSourceMap: sourceMappingUrl link not generated on rebuild #23

Closed blutorange closed 5 years ago

blutorange commented 5 years ago

Issue by tekhedd Wednesday Apr 12, 2017 at 18:44 GMT Originally opened as https://github.com/samaxes/minify-maven-plugin/issues/142


Using minify-maven-plugin 1.7.6.

When rebuilding a project using closureCreateSourceMap, the sourceMappingUrl is correctly generated on a clean build, but not inserted into the minified file on a rebuild.

My tests indicate that the //#sourceMappingUrl will be generated only if the original .js.map file does not exist. In other words, if I run

mvn clean ; mvn package

sourceMappingUrl is present. If I run 'mvn package' again without cleaning, sourceMappingUrl is missing.

If I manually remove target/exploded-dir/merged.min.js.map and then run 'mvn package' again, the sourceMappingUrl is generated.

The timestamp on the .map file is not changed, so it appears that closure is failing to regenerate it, hence the missing sourceMappingUrl line.

Workaround? Explicitly delete the source map file as part of the build, or always explicitly clean the target before deploying. (The target always runs regardless of whether it needs to be rebuilt, so in netbeans "clean and build" followed by "run" results in no map file.)

Note: all mvn runs performed with "-e" "-DskipTests" for this experiment. Hope this helps.

File names have been changed to protect the innocent.

   <plugin>
        <groupId>com.samaxes.maven</groupId>
        <artifactId>minify-maven-plugin</artifactId>
        <version>1.7.6</version>
        <executions>
            <execution>
                <id>minify</id>
                <phase>process-resources</phase>
                <goals>
                    <goal>minify</goal>
                </goals>
                <configuration>
                    <charset>UTF-8</charset>

                    <cssTargetDir>css</cssTargetDir>
                    <cssFinalFile>style.css</cssFinalFile>

                    <cssSourceDir>css</cssSourceDir>
                    <cssSourceFiles>
                               ...
                    </cssSourceFiles>

                    <jsTargetDir>.</jsTargetDir>
                    <jsFinalFile>final.js</jsFinalFile>
                    <closureCreateSourceMap>true</closureCreateSourceMap>
                    <nosuffix>false</nosuffix>

                    <jsSourceDir>.</jsSourceDir>
                    <!-- <jsSourceIncludes>*.js</jsSourceIncludes> -->
                    <jsSourceFiles>
                             ...
                    </jsSourceFiles>

                    <jsEngine>CLOSURE</jsEngine>
                    <closureCompilationLevel>SIMPLE_OPTIMIZATIONS</closureCompilationLevel>
                    <closureCreateSourceMap>true</closureCreateSourceMap>
                </configuration>
            </execution>
        </executions>
    </plugin>`
blutorange commented 5 years ago

Comment by tekhedd Wednesday Apr 12, 2017 at 19:05 GMT


FYI workaround: add this so that it will run before the minify plugin. (Note use of deprecated tasks element!) [updated to fix failure to build after clean]

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
            <execution>
                <id>minify-map-file-workaround</id>
                <!-- phase/goal must match minify-maven-plugin -->
                <phase>process-resources</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <tasks>
                        <delete>
                            <!-- Delete all map files found in the output dir. Output dir should exist by
                                 - this time in the build process even if it's a clean build. map file might not.
                                -->
                            <fileset dir="${project.build.directory}">
                                <!-- Caveat: if this is not the path to your map file, no error will occur. -->
                                <include name="${project.build.finalName}/*.map" />
                            </fileset>
                        </delete>
                    </tasks>
                </configuration>
            </execution>
        </executions>
    </plugin>
blutorange commented 5 years ago

Comment by ghost Tuesday May 02, 2017 at 16:40 GMT


+1

blutorange commented 5 years ago

Should be fixed via merging https://github.com/samaxes/minify-maven-plugin/pull/149