在
Maven
打包的时候可以使用YUI Compressor
(压缩CSS/JS)文件,使用yuicompressor-maven-plugin
插件进行压缩后会减小体积,提高请求速度。
在pom.xml
文件中增加该插件的定义,示例如下:
<build>
<plugins>
<!-- YUI Compressor (CSS/JS压缩) -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 读取js,css文件采用UTF-8编码 -->
<encoding>UTF-8</encoding>
<!-- 是否忽略警告 -->
<jswarn>false</jswarn>
<!-- 是否添加.min后缀 -->
<nosuffix>true</nosuffix>