mavenmaven-3yui-compressor

Maven & yui-compressor Plugin issues


I'm using the yui-compressor plugin for maven and can't seem to get it to compress. The appending of all js files works fine. It doesn't remove comments, line breaks and it doesn't minify the js (i.e. turn var myVar into var a). Is there something wrong with my configuration?

    <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>yuicompressor-maven-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>compress</goal>
                            </goals>
                            <configuration>
                                <jswarn>false</jswarn>
                                <disableOptimizations>false</disableOptimizations>
                                <insertNewLine>false</insertNewLine>
                                <preserveAllSemiColons>false</preserveAllSemiColons>
                                <aggregations>
                                    <aggregation>
                                        <removeIncluded>true</removeIncluded>
                                        <!-- insert new line after each concatenation (default: false) -->
                                        <output>${project.build.directory}/${project.build.finalName}/WEB-INF/scripts/all.js</output>
                                        <!-- files to include, path relative to output's directory or absolute 
                                            path -->
                                        <!--inputDir>base directory for non absolute includes, default to 
                                            parent dir of output</inputDir -->
                                        <includes>
                                            <include>${basedir}/src/main/webapp/WEB-INF/scripts/underscore.js</include>
<include>${basedir}/src/main/webapp/WEB-INF/scripts/backbone.dev.js</include>
<include>${basedir}/src/main/webapp/WEB-INF/scripts/modernizr.custom.83543.js</include>
<include>${basedir}/src/main/webapp/WEB-INF/scripts/jquery.slider.min.js</include>
<include>${basedir}/src/main/webapp/WEB-INF/scripts/myApp.js</include>
                                        </includes>
                                        <!-- files to exclude, path relative to output's directory <excludes> 
                                            <exclude>**/*.pack.js</exclude> <exclude>**/compressed.css</exclude> </excludes> -->
                                    </aggregation>
                                </aggregations>
                                <includes>
                                    <include>${basedir}/src/main/webapp/WEB-INF/scripts/*.js</include>
                                </includes>
                                <excludes>
                                    <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/*min*.js</exclude>
                                    <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/underscore.js</exclude>
                                    <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/backbone.js</exclude>
                                    <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/modernizr*.js</exclude>
                                    <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/*fancybox*.js</exclude>
                                    <exclude>${basedir}/src/main/webapp/WEB-INF/scripts/jquery.easing*.js</exclude>
                                </excludes>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

Solution

  • I figured out what was going on. Actually, there were a few things wrong: first, the entire configuration block needs to be adjacent to the executions block, not inside it. Second, the insertNewLine option needs to be inside the aggregation bock. Third, the comments that weren't being removed were /*! */ comments, which typically contains licensing info and yui-compressor doesn't remove. Fourth, and most importantly, myApp.js had an eval in it, which is considered "evil" and stops yui-compressor from compressing.

    Hope this helps people!