yuicompressor-maven-plugin插件-用于压缩js,css

实例1

<?xml version="1.0" encoding="utf-8"?>
 
 <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>com.test</groupId>
   <!-- 项目产品名称 -->
   <artifactId>test-mobile</artifactId>
   <!-- 项目产品版本 -->
   <version>1.0.0</version>
   <!-- pom属性配置 -->
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
   <!-- 构建相关配置  -->
   <build>
     <!-- maven插件配置 -->
     <plugins>
       <plugin>
         <!-- YUI Compressor Maven压缩插件 -->
         <groupId>net.alchim31.maven</groupId>
         <artifactId>yuicompressor-maven-plugin</artifactId>
         <version>1.3.0</version>
         <configuration>
           <!-- 读取js,css文件采用UTF-8编码 -->
           <encoding>UTF-8</encoding>
           <!-- 不显示js可能的错误 -->
           <jswarn>false</jswarn>
           <!-- 若存在已压缩的文件,会先对比源文件是否有改动。有改动便压缩,无改动就不压缩 -->
           <force>false</force>
           <!-- 在指定的列号后插入新行 -->
           <linebreakpos>-1</linebreakpos>
           <!-- 压缩之前先执行聚合文件操作 -->
           <preProcessAggregates>true</preProcessAggregates>
           <!-- 压缩后保存文件后缀 -->
           <suffix>.min</suffix>
           <!-- 源目录,即需压缩的根目录 -->
           <sourceDirectory>${basedir}/mobile</sourceDirectory>
           <!-- 压缩js和css文件 -->
           <includes>
             <include>**/*.js</include>
             <include>**/*.css</include>
           </includes>
           <!-- 以下目录和文件不会被压缩 -->
           <excludes>
             <exclude>**/*.min.js</exclude>
             <exclude>**/*.min.css</exclude>
             <exclude>scripts/data/*.js</exclude>
           </excludes>
           <!-- 压缩后输出文件目录 -->
           <outputDirectory>${basedir}/mobile</outputDirectory>
           <!-- 聚合文件 -->
           <aggregations>
             <aggregation>
               <!-- 合并每一个文件后插入一新行 -->
               <insertNewLine>true</insertNewLine>
               <!-- 需合并文件的根文件夹 -->
               <inputDir>${basedir}/mobile/scripts</inputDir>
               <!-- 最终合并的输出文件 -->
               <output>${basedir}/mobile/scripts/app/app.js</output>
               <!-- 把以下js文件合并成一个js文件,是按顺序合并的 -->
               <includes>
                 <include>app/core.js</include>
                 <include>app/mlmanager.js</include>
                 <include>app/tmpl.js</include>
                 <include>app/ui.js</include>
               </includes>
             </aggregation>
           </aggregations>
         </configuration>
       </plugin>
     </plugins>
   </build>
 </project>



实例2,,

<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>
                    <!-- 指定需要压缩文件的目录,这是我的目录(修改为你自己的目录吧..)${basedir}/assets是安装文件的根目录 -->
                    <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>


然后执行maven -install。

转载于:https://my.oschina.net/zhangyafei/blog/600088

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值