pom 配置:
<plugin> <groupId>net.alchim31.maven</groupId> <artifactId>yuicompressor-maven-plugin</artifactId> <version>1.5.1</version> <executions> <execution> <goals> <goal>jslint</goal> <goal>compress</goal> </goals> </execution> </executions> <configuration> <skip>false</skip> <!-- 读取js,css文件采用UTF-8编码 --> <encoding>UTF-8</encoding> <!-- 是否忽略警告 --> <jswarn>false</jswarn> <!-- 若存在已压缩的文件,会先对比源文件是否有改动。有改动便压缩,无改动就不压缩 --> <force>true</force> <!-- <suffix>.min</suffix> --> <!-- 是否添加 .min 后缀 --> <nosuffix>true</nosuffix> <!-- 是否压缩在一行,在指定的列号后插入新行 --> <linebreakpos>-1</linebreakpos> <!-- 压缩之前先执行聚合文件操作 --> <preProcessAggregates>true</preProcessAggregates> <sourceDirectory>src/main/resources/webapp</sourceDirectory> <includes> <include>**/webapp/js/**/*.js</include> <include>**/webapp/static/css/**/*.css</include> </includes> <excludes> <exclude>**/client/**</exclude> <exclude>**/static/vendor/**</exclude> </excludes> </configuration> </plugin>
项目路径如下:
打包后的js和css文件都是被压缩的,如下图: