您的位置:首页 > Web前端 > CSS

使用yuicompressor 压缩js,css并发布程序 (Maven)

2018-09-05 18:49 260 查看

看了网上很多方法,只有自己写的才适合自己:

  1. 首先更新最新代码,确定需要打包项目pom.xml有以下插件配置(根据自己需要进行配置)

<build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.5.1</version>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <jswarn>false</jswarn>
                    <nosuffix>true</nosuffix>
                    <force>true</force>
                    <!-- 压缩之前先执行聚合文件操作 -->
                    <preProcessAggregates>true</preProcessAggregates>
                    <linebreakpos>-1</linebreakpos>
                    <sourceDirectory>WebContent</sourceDirectory>
                    <includes>
                        <include>res/**/*.js</include>
                        <include>res/**/*.css</include>
                    </includes>

                   <!--  编译出错的就不要了-->
                     <excludes>
                        <!-- <exclude>res/**/*min.js</exclude>
                        <exclude>res/**/*min.css</exclude>-->
                        <exclude>res/**/*jquery-dev.js</exclude> 
                        <exclude>res/**/*echarts.min.js</exclude>
                    </excludes> 

                    <!-- 输出到需要打包的路径下面很重要 -->
                    <outputDirectory>target/jfat-ecctv-webapp</outputDirectory>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                       <!--指定web.xml的路径  -->  
                    <webXml>WebContent\WEB-INF\web.xml</webXml>  
                    <!--指定jsp、js、css,png的路劲  -->  
                     <warSourceIncludes>
                            **/*jquery-dev.js,
                            **/*echarts.min.js,
                            **/tmpl/**/*,
                            META-INF/**,
                            **/*.xml,
                            **/*.jsp,
                            **/*.gif,
                            **/*.jpg,
                            **/*.png
                    </warSourceIncludes>
                </configuration>
            </plugin>

</plugins>

</build>

  1. 首先,确保项目所有模块jdk版本都在7以上。
  2. 更新项目后,选中需要打包的模块,右键项目名称,选中Run As。
  3. 在展开的页面点击Maven Clean,控制台显示成功后执行下一步。
  4. 然后执行Maven install 将项目本身编译并打包。打包过程中会执行Js和Css的压缩,成功后在控制台会显示产生的war包路径(如下图)。

欢迎访问:http://lhylyw.ngrok.xiaomiqiu.cn/   

免费下载各种课程设计和学习资源

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: