本文介绍通过使用yuicompressor-maven-plugin插件实现js及css代码的自动压缩,加快访问速度,同时方便集成到持续集成环境中。
一、更改pom.xml配置文件,添加yuicompressor-maven-plugin插件
<build>
......
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
<!-- 忽略 js 错误警告 -->
<jswarn>false</jswarn>
<nosuffix>true</nosuffix>
<linebreakpos>-1</linebreakpos>
<includes>
<include>**/**/*.js</include>
<include>**/**/*.css</include>
</includes>
<excludes>
<exclude>**/**min.js</exclude>
</excludes>
<aggregations>
<!-- 合并压缩JS -->
<aggregation>
<remo