使用ANT与YUI压缩js的实现方法
作者:互联网
2025-08-20
由于项目使用的js很多,为了提高系统效率,将js做压缩处理。
成功的对多个js进行压缩,必须经历下面两步。
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="创建build目录" >
< mkdir dir="${build}"/ >
< /target >
复制代码代码如下:
< !-- 将多个js合并成为一个js -- >
< target name="合并js" depends="创建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 >
< !-- 复制压缩后的js文件 -- >
< antcall target="复制压缩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="复制压缩js文件" >
< copy todir="${map_function_js}" >
< fileset dir="${build}" >
< include name="**.js"/ >
< /fileset >
< /copy >
< /target >
相关标签:
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
ReentrantReadWriteLock、ReentrantLock、synchronized 对比
MySQL性能优化的天花板:10条你必须掌握的顶级SQL分析技巧
大V说’AI替代不了你’,但现实是——用AI的人正在替代你
手写 Spring AI Agent:让大模型自主规划任务,ReAct 模式全流程拆解
一文讲透单点登录原理(SSO):从同域共享到跨域票据
【SpringAIAlibaba新手村系列】(18)Agent 智能体与今日菜单应用
CompletableFuture 异步编程全解:核心能力、编排方案、异常处理与超时控制
【从0到1构建一个ClaudeAgent】规划与协调-技能
Spring AI Advisors:从链式增强到递归顾问
ReentrantLock 与 synchronized对比
AI精选
