使用ANT與YUI壓縮js的實現(xiàn)方法
更新時間:2013年05月17日 09:01:49 作者:
本篇文章是對使用ANT與YUI壓縮js的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友參考下
由于項目使用的js很多,為了提高系統(tǒng)效率,將js做壓縮處理。
成功的對多個js進行壓縮,必須經(jīng)歷下面兩步。
1.合并多個js成為一個js.
2.將和并過后的js進行壓縮處理。
使用的ant配置主要有:
<property name="root" value="WebRoot"></property>
<property name="js" value="${root}/js"></property>
<property name="map_function_js" value="${js}/mapfunc"></property>
<property name="lib" value="lib"/>
<property name="build" value="build"></property>
<property name="war" value="war"></property>
<property name="war.info" value="${war}/WEB-INF"></property>
<property name="war.lib" value="${war.info}/lib"></property>
<property name="war.classes" value="${war.info}/classes"></property>
<property name="project.name" value="zjmap"></property>
<property name="charset" value="utf-8"/>
<property name="src" value="src"/>
<target name="創(chuàng)建build目錄">
<mkdir dir="${build}"/>
</target>
<!-- 將多個js合并成為一個js -->
<target name="合并js" depends="創(chuàng)建build目錄">
<concat destfile="${build}/mapfuncall.js" encoding="${charset}" outputencoding="${charset}">
<path path="${map_function_js}/DC.js" />
<path path="${map_function_js}/stringUtil.js" />
<path path="${map_function_js}/LOCALDC.js" />
<path path="${map_function_js}/screen.js" />
<path path="${map_function_js}/wfsQuery.js" />
<path path="${map_function_js}/Map.js" />
<path path="${map_function_js}/Query.js" />
<path path="${map_function_js}/ClassificationQuery.js" />
<path path="${map_function_js}/BusQuery.js" />
<path path="${map_function_js}/RouteQuery.js" />
<path path="${map_function_js}/cursorPosition.js" />
<path path="${map_function_js}/bufferAnalysis.js" />
<path path="${map_function_js}/divCtrl.js" />
<path path="${map_function_js}/mark.js" />
<path path="${map_function_js}/overlayAnalysis.js" />
<path path="${map_function_js}/BuildQuery.js" />
<path path="${map_function_js}/PopShow.js" />
<path path="${map_function_js}/correct.js" />
<path path="${map_function_js}/style_result.js" />
<path path="${map_function_js}/style_ui.js" />
<path path="${map_function_js}/Catalog.js" />
<path path="${map_function_js}/scenario.js" />
<path path="${map_function_js}/wfs.js" />
<path path="${map_function_js}/Uuid.js" />
<path path="${map_function_js}/Gps.js" />
<path path="${map_function_js}/typhoon.js" />
<path path="${map_function_js}/Monitor.js" />
<path path="${map_function_js}/RainWater.js" />
<path path="${map_function_js}/Approval.js" />
<path path="${map_function_js}/statistics.js" />
<path path="${map_function_js}/statisticsNew.js" />
<path path="${map_function_js}/OTileCacheCustom.js" />
<path path="${map_function_js}/BQTool.js" />
<path path="${map_function_js}/CityPositionQuery.js" />
<path path="${map_function_js}/IFieldService.js" />
<path path="${map_function_js}/SpecialQuery.js" />
</concat>
<replaceregexp match="@DEBUG@" replace="" flags="g" byline="true" file="${build}/mapfuncall.js" encoding="${charset}" />
</target>
<!-- 使用雅虎UI進行js壓縮 -->
<target name="開始壓縮" depends="合并js">
<!-- 使用雅虎UI壓縮 mapfuncall.js -->
<antcall target="壓縮mapfuncall.js"></antcall>
<!-- 使用雅虎UI壓縮 dataedit.js -->
<antcall target="壓縮dataedit.js"></antcall>
<!-- 使用雅虎UI壓縮 ISuggest.js -->
<antcall target="壓縮ISuggest.js"></antcall>
<!-- 復(fù)制壓縮后的js文件 -->
<antcall target="復(fù)制壓縮js文件"></antcall>
</target>
<target name="壓縮mapfuncall.js">
<java jar="${lib}/yui/yuicompressor-2.4.6.jar" fork="true">
<arg line="--type js --charset utf-8 ${map_function_js}/mapfuncall.js -o ${build}/mapfuncall-min.js"/>
</java>
</target>
<target name="壓縮dataedit.js">
<java jar="${lib}/yui/yuicompressor-2.4.6.jar" fork="true">
<arg line="--type js --charset utf-8 ${map_function_js}/dataedit.js -o ${build}/dataedit-min.js"/>
</java>
</target>
<target name="壓縮ISuggest.js">
<java jar="${lib}/yui/yuicompressor-2.4.6.jar" fork="true">
<arg line="--type js --charset utf-8 ${map_function_js}/ISuggest.js -o ${build}/ISuggest-min.js"/>
</java>
</target>
<target name="清除build目錄" depends="開始壓縮">
<delete dir="${build}"/>
</target>
<target name="復(fù)制壓縮js文件">
<copy todir="${map_function_js}">
<fileset dir="${build}">
<include name="**.js"/>
</fileset>
</copy>
</target>
成功的對多個js進行壓縮,必須經(jīng)歷下面兩步。
1.合并多個js成為一個js.
2.將和并過后的js進行壓縮處理。
使用的ant配置主要有:
復(fù)制代碼 代碼如下:
<property name="root" value="WebRoot"></property>
<property name="js" value="${root}/js"></property>
<property name="map_function_js" value="${js}/mapfunc"></property>
<property name="lib" value="lib"/>
<property name="build" value="build"></property>
<property name="war" value="war"></property>
<property name="war.info" value="${war}/WEB-INF"></property>
<property name="war.lib" value="${war.info}/lib"></property>
<property name="war.classes" value="${war.info}/classes"></property>
<property name="project.name" value="zjmap"></property>
<property name="charset" value="utf-8"/>
<property name="src" value="src"/>
<target name="創(chuàng)建build目錄">
<mkdir dir="${build}"/>
</target>
復(fù)制代碼 代碼如下:
<!-- 將多個js合并成為一個js -->
<target name="合并js" depends="創(chuàng)建build目錄">
<concat destfile="${build}/mapfuncall.js" encoding="${charset}" outputencoding="${charset}">
<path path="${map_function_js}/DC.js" />
<path path="${map_function_js}/stringUtil.js" />
<path path="${map_function_js}/LOCALDC.js" />
<path path="${map_function_js}/screen.js" />
<path path="${map_function_js}/wfsQuery.js" />
<path path="${map_function_js}/Map.js" />
<path path="${map_function_js}/Query.js" />
<path path="${map_function_js}/ClassificationQuery.js" />
<path path="${map_function_js}/BusQuery.js" />
<path path="${map_function_js}/RouteQuery.js" />
<path path="${map_function_js}/cursorPosition.js" />
<path path="${map_function_js}/bufferAnalysis.js" />
<path path="${map_function_js}/divCtrl.js" />
<path path="${map_function_js}/mark.js" />
<path path="${map_function_js}/overlayAnalysis.js" />
<path path="${map_function_js}/BuildQuery.js" />
<path path="${map_function_js}/PopShow.js" />
<path path="${map_function_js}/correct.js" />
<path path="${map_function_js}/style_result.js" />
<path path="${map_function_js}/style_ui.js" />
<path path="${map_function_js}/Catalog.js" />
<path path="${map_function_js}/scenario.js" />
<path path="${map_function_js}/wfs.js" />
<path path="${map_function_js}/Uuid.js" />
<path path="${map_function_js}/Gps.js" />
<path path="${map_function_js}/typhoon.js" />
<path path="${map_function_js}/Monitor.js" />
<path path="${map_function_js}/RainWater.js" />
<path path="${map_function_js}/Approval.js" />
<path path="${map_function_js}/statistics.js" />
<path path="${map_function_js}/statisticsNew.js" />
<path path="${map_function_js}/OTileCacheCustom.js" />
<path path="${map_function_js}/BQTool.js" />
<path path="${map_function_js}/CityPositionQuery.js" />
<path path="${map_function_js}/IFieldService.js" />
<path path="${map_function_js}/SpecialQuery.js" />
</concat>
<replaceregexp match="@DEBUG@" replace="" flags="g" byline="true" file="${build}/mapfuncall.js" encoding="${charset}" />
</target>
<!-- 使用雅虎UI進行js壓縮 -->
<target name="開始壓縮" depends="合并js">
<!-- 使用雅虎UI壓縮 mapfuncall.js -->
<antcall target="壓縮mapfuncall.js"></antcall>
<!-- 使用雅虎UI壓縮 dataedit.js -->
<antcall target="壓縮dataedit.js"></antcall>
<!-- 使用雅虎UI壓縮 ISuggest.js -->
<antcall target="壓縮ISuggest.js"></antcall>
<!-- 復(fù)制壓縮后的js文件 -->
<antcall target="復(fù)制壓縮js文件"></antcall>
</target>
<target name="壓縮mapfuncall.js">
<java jar="${lib}/yui/yuicompressor-2.4.6.jar" fork="true">
<arg line="--type js --charset utf-8 ${map_function_js}/mapfuncall.js -o ${build}/mapfuncall-min.js"/>
</java>
</target>
<target name="壓縮dataedit.js">
<java jar="${lib}/yui/yuicompressor-2.4.6.jar" fork="true">
<arg line="--type js --charset utf-8 ${map_function_js}/dataedit.js -o ${build}/dataedit-min.js"/>
</java>
</target>
<target name="壓縮ISuggest.js">
<java jar="${lib}/yui/yuicompressor-2.4.6.jar" fork="true">
<arg line="--type js --charset utf-8 ${map_function_js}/ISuggest.js -o ${build}/ISuggest-min.js"/>
</java>
</target>
<target name="清除build目錄" depends="開始壓縮">
<delete dir="${build}"/>
</target>
<target name="復(fù)制壓縮js文件">
<copy todir="${map_function_js}">
<fileset dir="${build}">
<include name="**.js"/>
</fileset>
</copy>
</target>
相關(guān)文章
spring聲明式事務(wù)@Transactional開發(fā)常犯的幾個錯誤及最新解決方案
使用聲明式事務(wù)@Transactional進行事務(wù)一致性的管理,在開發(fā)過程中,發(fā)現(xiàn)很多開發(fā)同學(xué)都用錯了spring聲明式事務(wù)@Transactional或使用不規(guī)范,導(dǎo)致出現(xiàn)各種事務(wù)問題,這篇文章主要介紹了spring聲明式事務(wù)@Transactional開發(fā)常犯的幾個錯誤及解決辦法,需要的朋友可以參考下2024-02-02
Java與Scala創(chuàng)建List與Map的實現(xiàn)方式
這篇文章主要介紹了Java與Scala創(chuàng)建List與Map的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10
java 解決異常 2 字節(jié)的 UTF-8 序列的字節(jié)2 無效的問題
這篇文章主要介紹了java 解決異常 2 字節(jié)的 UTF-8 序列的字節(jié) 2 無效的問題的相關(guān)資料,需要的朋友可以參考下2016-12-12
springmvc實現(xiàn)跨服務(wù)器文件上傳功能
這篇文章主要為大家詳細介紹了springmvc實現(xiàn)跨服務(wù)器文件上傳功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-08-08
Springboot使用Redis中ZSetOperations實現(xiàn)博客訪問量
在日常的網(wǎng)站使用中,經(jīng)常會碰到頁面的訪問量,本文主要介紹了Springboot使用Redis中ZSetOperations實現(xiàn)博客訪問量,具有一定的參考價值,感興趣的可以了解一下2024-01-01
JAVA基本類型包裝類 BigDecimal BigInteger 的使用
Java 中預(yù)定義了八種基本數(shù)據(jù)類型,包括:byte,int,long,double,float,boolean,char,short,接下來文章小編將向大家介紹其中幾個類型的內(nèi)容,需要的朋友可以參考下文章2021-09-09
spring boot項目導(dǎo)入依賴后代碼報錯問題的解決方法
這篇文章主要給大家介紹了關(guān)于spring boot項目導(dǎo)入依賴后代碼報錯問題的解決方法,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用spring Boot具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08

