Usage of YUI Compressor Maven Mojo minifying javascript

孤者浪人 提交于 2019-12-06 13:40:24

I have found working solution here. Basically you need to place the following into you pom.xml (replacing only the path to you js and css files inside src/main/webapp folder):

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <!-- Add minified resources -->
                    <resource>
                        <directory>${project.build.directory}/minimized</directory>
                        <targetPath>/</targetPath>
                        <filtering>false</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <nosuffix>true</nosuffix>
            </configuration>
        </plugin>
    </plugins>

    <pluginManagement>
        <plugins>
            <!-- Javascript and CSS files compression -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <!-- Don't output in the default webapp location, since the war plugin will overwrite the files in there
                    with the original, uncompressed ones. -->
                    <webappDirectory>${project.build.directory}/minimized</webappDirectory>
                    <jswarn>false</jswarn>
                    <!-- Overwrite existing files -->
                    <nosuffix>true</nosuffix>
                    <includes>
                        <include>%path to your js and css files inside src/main/webapp%/**/*</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    </build>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!