摘要:本文将带你了解WEBAPP开发Maven插件wro4j-maven-plugin压缩、合并js、css详解,希望本文对大家学WEBAPP有所帮助。
本文将带你了解WEBAPP开发Maven插件wro4j-maven-plugin压缩、合并js、css详解,希望本文对大家学WEBAPP有所帮助。
1. 在pom.xml文件中,引入wro4j-maven-plugin插件
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<id>optimize-web-resources</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<ignoreMissingResources>false</ignoreMissingResources>
<jsDestinationFolder>
${project.build.directory}/${project.build.finalName}/static/js
</jsDestinationFolder>
<cssDestinationFolder>
${project.build.directory}/${project.build.finalName}/static/css
</cssDestinationFolder>
<wroManagerFactory>
ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory
</wroManagerFactory>
</configuration>
</plugin>
2. 配置合并、压缩策略,新建文件/WEB-INF/wro.xml,例如配置内容为:
<?xml version="1.0" encoding="UTF-8"?>
<groups xmlns="//www.isdc.ro/wro" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="//www.isdc.ro/wro wro.xsd">
<group name="basic">
<css>/static/css/front.css</css>
<js>/static/js/jquery.js</js>
<js>/static/js/jquery.paging.min.js</js>
<js>/static/js/front/global.js</js>
<js>/static/js/front/search.js</js>
</group>
<group name="custom">
<css>/static/css/front.css</css>
<css>/static/css/comment/comment.css</css>
<css>/static/plugins/syntaxhighlighter/shCore.css</css>
<js>/static/js/front/coding.js</js>
</group>
</groups>
3. 配置wro4j相关属性,新建WEB-INF/wro.properties,例如配置内容为:
cacheUpdatePeriod=0
modelUpdatePeriod=0
debug=true
disableCache=false
gzipResources=true
ignoreMissingResources=false
此插件必须配置wro.properties。否则在执行打包命令:clean package时否则会报如下异常:
src\main\webapp\WEB-INF\wro.properties (系统找不到指定的文件。) -> [Help 1]
4. 执行maven命令:clean package 打包
我们会发现根据wro.xml配置的策略在
${project.build.directory}/${project.build.finalName}/static/js
${project.build.directory}/${project.build.finalName}/static/css的目录下生成了
basic.css、basic.js、custom.css、custom.js等合并压缩后的文件。
Maven插件wro4j-maven-plugin压缩、合并js、css详解
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之WebApp频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号