使用maven插件压缩js和css文件

重复记载只为自己日后方便查找

参考地址: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就会进行压缩

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值