`
381895649
  • 浏览: 227983 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

maven 利用 yuicompressor-maven-plugin 打包压缩静态资源文件

 
阅读更多

HK 学习笔记

 

下面是利用  maven yuicompressor-maven-plugin 打包静态资源文件

 

费话不多说了,直接看配置文件就好了

 

现在我用的是  yuicompressor-maven-plugin 1.3.0,如果需要升级了,大家自己修改版本吧

 

 

 

<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>xrk_assets</groupId>
	<artifactId>xrk_assets</artifactId>
	<version>0.0.1</version>
	<packaging>jar</packaging>
	<build>
		<!-- 利用yuicompressor-maven-plugin 插件,当打包项目时,自动压缩文件 -->
		<plugins>
			<plugin>
				<groupId>net.alchim31.maven</groupId>
				<artifactId>yuicompressor-maven-plugin</artifactId>
				<version>1.3.0</version>
				<executions>
					<execution>
						<goals>
							<goal>compress</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<!-- 压缩文件编码 -->
					<encoding>GBK</encoding>
					<!-- 排除已压缩的文件,例如jquery-1.8.2.min.js -->
					<excludes>
						<exclude>**/**.min.js</exclude>
					</excludes>
					<!-- 不使用后缀 -->
					<nosuffix>true</nosuffix>
					<!-- 把文件压缩成一行 -->
					<linebreakpos>-1</linebreakpos>
					<!-- 指定需要压缩文件的目录,这是我的目录(修改为你自己的目录吧..) -->
					<sourceDirectory>${basedir}/assets</sourceDirectory>
				</configuration>
			</plugin>
		</plugins>
		<resources>
			<!-- 直接复制不用压缩的文件,图片,已经压缩的css,js -->
			<resource>
				<directory>${basedir}/assets</directory>
				<includes>
					<include>**/**.min.js</include>
					<include>**/images/**</include>
				</includes>
			</resource>
		</resources>
	</build>
</project>

 

 

 配置好后,运行mvn clean package ,就可以把想压缩的静态文件,成功压缩!!

 

本文章来自:http://blog.mkfree.com/posts/7

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics