您的位置:首页 > 产品设计 > UI/UE

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

2016-01-09 00:00 639 查看
实例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>
&n
7fe8
bsp; <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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  maven js css压缩