Maven壓縮插件YUI Compressor使用介紹

簡介 這篇文章主要介紹了Maven壓縮插件YUI Compressor使用介紹以及相關的經驗技巧,文章約18810字,瀏覽量165,點贊數5,值得參考!

使用這個插件主要有兩個作用:

  1. 減少資源文件體積,提高移動端頁面加載速度。

  2. 對關鍵的前端代碼進行一定的代碼混淆,保護知識產權。

使用說明:

使用YUI Compressor壓縮JS和CSS。

需要Maven2.0及以上工程。

默認情況綁定到構建生命週期:process-resources。

配置說明:

請在pom.xml文件填上配置項

依賴配置:


<dependencies>

    <dependency>

        <groupId>net.alchim31.maven</groupId>

        <artifactId>yuicompressor-maven-plugin</artifactId>

        <version>1.5.1</version>

    </dependency>

</dependencies>

構建配置:


<build>

    <plugins>

        <plugin>

            <groupId>net.alchim31.maven</groupId>

            <artifactId>yuicompressor-maven-plugin</artifactId>

            <version>1.5.1</version>

            <executions>

                <execution>

                    <phase>process-resources</phase>

                    <goals>

                        <goal>compress</goal>

                    </goals>

                </execution>

            </executions>

            <configuration>

                <encoding>UTF-8</encoding>

                <jswarn>false</jswarn>

                <nosuffix>true</nosuffix>

                <linebreakpos>-1</linebreakpos>

                <sourceDirectory>${project.build.directory}/classes/h5 </sourceDirectory>

                <outputDirectory>${project.build.directory}/classes/h5</outputDirectory>

                <includes>

                    <include>**/js/*.js</include>

                    <include>**/css/*.css</include>

                </includes>

                <excludes>

                    <exclude>**/js/*min.js</exclude>

                    <exclude>**/css/*min.css</exclude>

                </excludes>

            </configuration>

        </plugin>

    </plugins>

</build>

其中標紅項爲自定義項,請大家結合自己的情況
參數說明

名稱 類型 描述
aggregations Aggregation[] 處理後要執行的聚合/連接列表,例如創建包含多個小js文件的大js文件。 聚合可以在任何類型的文件(js,css,...)上完成。
disableOptimizations boolean [js only]禁用所有微優化。默認值:false
encoding String 讀取文件使用的編碼。默認值:UTF-8
excludes List 附加排除列表。
failOnWarning boolean 定義插件是否必須在警告上停止/失敗。默認值:false
force boolean 強制壓縮每個文件,否則如果壓縮文件已存在並且比源文件新,則不執行任何操作。默認值:false
gzip boolean 請求創建yui 壓縮/ 聚合文件的gzip壓縮版本。默認值:false
jswarn boolean [js only]顯示代碼中可能存在的錯誤。默認值:true
linebreakpos int 在指定的列號後面的輸出中插入換行符,-1表示壓縮成1行。默認值:0。
nomunge boolean [js only]僅縮小,不要混淆。默認值:false(壓縮並混淆)
nosuffix boolean 不給壓縮文件添加後綴,參考suffix參數,如min。默認值:false(添加後綴)
outputDirectory File 要將資源複製到的輸出目錄。
preserveAllSemiColons boolean [js only]保留不必要的分號。默認值:false(不保留)
resources List 我們要傳輸的資源列表。
skip boolean 是否跳過執行。默認值:false
sourceDirectory File Javascript源目錄(結果將被放到outputDirectory)。 允許項目具有“src/main/js”結構。
statistics boolean 顯示統計數據(壓縮率)。默認值:true
suffix String 輸出文件名後綴。默認值:-min
warSourceDirectory File 要包含在WAR中的額外文件的單個目錄。
webappDirectory File 構建webapp的目錄。

轉載自:http://www.136.la/jingpin/show-95608.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章