JS,CSS, Maven打包压缩合并

Maven项目Pom文件中添加

<build>
		<plugins>
			<plugin>
				<groupId>net.alchim31.maven</groupId>
				<artifactId>yuicompressor-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>yuicompressor</id>
						<phase>prepare-package</phase>
						<goals>
							<goal>compress</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<!-- 读取js,css文件采用UTF-8编码 -->
					<encoding>UTF-8</encoding>
					<!-- 不显示js可能的错误 -->
					<jswarn>false</jswarn>
					<!-- 若存在已压缩的文件,会先对比源文件是否有改动 有改动便压缩,无改动就不压缩 -->
					<force>false</force>
					<!-- 在指定的列号后插入新行 -->
					<linebreakpos>-1</linebreakpos>
					<!-- 压缩之前先执行聚合文件操作 -->
					<preProcessAggregates>false</preProcessAggregates>
					<!-- 压缩后保存文件后缀 
					<suffix>.min</suffix>
					-->
					<nosuffix>true</nosuffix>
					<!-- 压缩js和css文件 -->
					<includes>
						<include>**/*.js</include>
						<include>**/*.css</include>
					</includes>
					<!-- 以下目录和文件不会被压缩 -->
					<excludes>
						<exclude>**/*.min.css</exclude>
						<exclude>**/*-min.css</exclude>
						<exclude>**/*.min.js</exclude>
						<exclude>**/*-min.js</exclude>
					</excludes>
					<!-- 压缩文件 -->
					<aggregations>
					    <!-- css 文件压缩成一个文件  -->
						<aggregation>
							<!-- 合并每一个文件后插入一新行 -->
							<insertNewLine>true</insertNewLine>
							<!-- 需合并文件的根文件夹 -->
							<inputDir>${project.build.directory}</inputDir>
							<!-- 最终合并的输出文件 -->
							<output>${project.build.directory}/${project.build.finalName}/staicfile/css/selcss.pack.css</output>
							<!-- 把以下js文件合并成一个js文件,是按顺序合并的 -->
							<includes>
								<include>**/css/*.css</include>
							</includes>
						</aggregation>
						<!-- js 文件压缩成一个文件  -->
						<aggregation>
							<insertNewLine>true</insertNewLine>
							<inputDir>${project.build.directory}</inputDir>
							<output>${project.build.directory}/${project.build.finalName}/staicfile/js/seljs.pack.js</output>
							<includes>
								<include>**/js/*.js</include>
							</includes>
							<excludes>
								<exclude>**/*.min.js</exclude>
								<exclude>**/*-min.js</exclude>
							</excludes>
						</aggregation>
					</aggregations>
				</configuration>
			</plugin>

猜你喜欢

转载自pluto418.iteye.com/blog/1867547
今日推荐