重复记载只为自己日后方便查找
参考地址:http://www.cnblogs.com/gao241/p/3177268.html
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name/>
<description/>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dui.devMode>false</dui.devMode>
<dui.suffix>.min</dui.suffix>
</properties>
<!-- 指定Maven仓库 -->
<repositories>
<!-- oschina的maven仓库 -->
<repository>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<!-- 官方maven仓库 -->
<repository>
<id>maven</id> <name>Maven Repository Switchboard</name>
<layout>default</layout> <url>http://repo1.maven.org/maven2</url>
<snapshots> <enabled>true</enabled> </snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<!-- YUI Compressor Maven压缩插件 -->
<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>
<skip>${dui.devMode}</skip>
<encoding>UTF-8</encoding>
<jswarn>false</jswarn>
<force>false</force>
<suffix>${dui.suffix}</suffix>
<!-- 没有文件后缀即没有min -->
<nosuffix>true</nosuffix>
<!--此处过滤不压缩的文件-->
<excludes>
<exclude>**/*.min.js</exclude>
<exclude>**/*.min.css</exclude>
<exclude>**/jslib/angular/**/*.*</exclude>
<exclude>**/jslib/app/app.js</exclude>
<exclude>**/jslib/app/directive.js</exclude>
<exclude>**/jslib/app/filter.js</exclude>
<exclude>**/jslib/plugins/**/*.*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceExcludes>**/*.js,**/*.css</warSourceExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
include节点用于配置需要压缩的文件路径,可以使用通配符,*表示一个文件或路径名,**表示多个文件或路径名,exclude节点用于配置排除压缩的文件路径,exclude只会排除include中设置的路径下的文件或路径。
压缩的js中不能存在特殊的串 比如 import、debugger等,压缩会报错
最后只要maven install就会进行压缩