maven js css 自动压缩

时间:2025-03-24 08:03:37

找了半天只有下面这个好使

参考:/zhangt85/article/details/41211297

中加上下面的,然后右键run maven clean package


如果下面plugin报错,不要 用  <pluginManagement>把plugin元素包起来,会导致无效,报错的话,

使用 <action> <ignore></ignore></action> 使用 /articles/RRjm6vv


l另外可以参考:http:///2014/09/ 

<!-- 配合打包用,不加的话,打包出来的还是没压缩的  因为就算先压缩了,后面编译的时候,还会覆盖掉--> 

<plugin>
<groupId></groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version> 
<configuration>
<warSourceExcludes>**/*.js,**/*.css</warSourceExcludes>
</configuration>
</plugin>
<plugin>
<!-- YUI Compressor Maven压缩插件 -->
<groupId>net.</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>process-resources</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>true</preProcessAggregates>
<!-- 压缩后保存文件后缀 无后缀 -->
<nosuffix>true</nosuffix>
<!-- 源目录,即需压缩的根目录 -->
<sourceDirectory>src/main/webapp/resource</sourceDirectory>
<!-- 压缩js和css文件 -->
<includes>
<include>**/*.js</include>
<include>**/*.css</include>
</includes>
<!-- 以下目录和文件不会被压缩 -->
<excludes>
<exclude>**/*.</exclude>
<exclude>**/*.</exclude>
<exclude>**/*.</exclude>
</excludes>


</configuration>

</plugin>