Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closureCreateSourceMap: sourceMappingUrl link not generated on rebuild #23

Closed
blutorange opened this issue Oct 14, 2018 · 3 comments
Closed

Comments

@blutorange
Copy link
Owner

Issue by tekhedd
Wednesday Apr 12, 2017 at 18:44 GMT
Originally opened as samaxes#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
Copy link
Owner Author

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
Copy link
Owner Author

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


+1

@blutorange
Copy link
Owner Author

Should be fixed via merging samaxes#149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant