zoukankan      html  css  js  c++  java
  • Maven插件wro4j-maven-plugin压缩、合并js、css详解

    1.    在pom.xml文件中,引入wro4j-maven-plugin插件

    1. <plugin>
    2.     <groupId>ro.isdc.wro4j</groupId>
    3.     <artifactId>wro4j-maven-plugin</artifactId>
    4.     <version>${wro4j.version}</version>
    5.  
    6.     <executions>
    7.         <execution>
    8.             <id>optimize-web-resources</id>
    9.             <phase>compile</phase>
    10.             <goals>
    11.                 <goal>run</goal>
    12.             </goals>
    13.         </execution>
    14.     </executions>
    15.  
    16.     <configuration>
    17.         <ignoreMissingResources>false</ignoreMissingResources>
    18.         <jsDestinationFolder>
    19.             ${project.build.directory}/${project.build.finalName}/static/js
    20.         </jsDestinationFolder>
    21.         <cssDestinationFolder>
    22.             ${project.build.directory}/${project.build.finalName}/static/css
    23.         </cssDestinationFolder>
    24.         <wroManagerFactory>
    25.             ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory
    26.         </wroManagerFactory>
    27.     </configuration>
    28. </plugin>



    2.    配置合并、压缩策略,新建文件/WEB-INF/wro.xml,例如配置内容为:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <groups xmlns="http://www.isdc.ro/wro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3.     xsi:schemaLocation="http://www.isdc.ro/wro wro.xsd">
    4.     <group name="basic">
    5.         <css>/static/css/front.css</css>
    6.         <js>/static/js/jquery.js</js>
    7.         <js>/static/js/jquery.paging.min.js</js>
    8.         <js>/static/js/front/global.js</js>
    9.         <js>/static/js/front/search.js</js>
    10.     </group>
    11.  
    12.     <group name="custom">
    13.         <css>/static/css/front.css</css>
    14.         <css>/static/css/comment/comment.css</css>
    15.         <css>/static/plugins/syntaxhighlighter/shCore.css</css>
    16.         <js>/static/js/front/coding.js</js>
    17.     </group>
    18.  
    19. </groups>

    3.    配置wro4j相关属性,新建WEB-INF/wro.properties,例如配置内容为:
    配置属性含义参见:http://everycoding.com/coding/68.html

    1. cacheUpdatePeriod=0
    2. modelUpdatePeriod=0
    3. debug=true
    4. disableCache=false
    5. gzipResources=true
    6. ignoreMissingResources=false

    此插件必须配置wro.properties。否则在执行打包命令:clean package时否则会报如下异常:
    srcmainwebappWEB-INFwro.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等合并压缩后的文件。

  • 相关阅读:
    What's different between Ctrl+Z and Ctrl+C in Unix command line?
    bitbucket使用,经验总结
    SpringMVC 强大的注解方式,走一个流程,看看,这些注解用过么
    java异常处理,需要考虑的流程
    两个日期之间相差的天数
    vue 路由面试题
    promise
    es6面试题
    谈谈你是如何理解 JS 异步编程的,EventLoop、消息队列都是做什么的,什么是宏任务,什么是微任务?
    使用高阶函数实现Array对象的方法
  • 原文地址:https://www.cnblogs.com/zhangtan/p/7610435.html
Copyright © 2011-2022 走看看