使用YUI+Ant 实现JS CSS压缩
今天研究了一下YUIyahoo开源框架,感觉很猛啊。
于是乎我做了一个YUI的ant实现,网上好多关于bat的实现,我就另辟蹊径,出个关于这个的ant实现,嘿嘿独一无二的文章,如果转载的话,其注明作者和网站
copyright:Mr.chen
好了具体操作如下:
官网:
yuicompressor-2.4.6.jar下载地址http://yuilibrary.com/downloads/#yuicompressor
YUIAnt.jar下载地址http://www.ubik-ingenierie.com/miscellanous/YUIAnt/
具体的相关代码如下:
#cssworkdir
commonCss.dir=css
#jsworkdir
commonJs.dir=js
#buildtempdir
output.temp.dir=build
#outputfilesinthedirectory
output.dir=${output.temp.dir}_output
#environmentneedslib
liblib=lib
<?xmlversion="1.0"encoding="UTF-8"?>
<projectname="CompressCSS-JS"default="compress"basedir=".">
<propertyfile="bulid.properties"/>
<pathid="yuiClasspath">
<filesetdir="${lib}">
<includename="*.*"/>
</fileset>
</path>
<!--#######################Inittheenvironmentofthetool##########################-->
<targetname="init">
<echomessage="begintoinittheinit"/>
<echomessage="deleteallreferencefiles."/>
<deletedir="${output.dir}"/>
<echomessage="deleteend"/>
<echomessage="makethereferencefiles."/>
<mkdirdir="${output.dir}"/>
<mkdirdir="${output.temp.dir}"/>
<echomessage="makeend."/>
</target>
<!--#######################Combinethecssfiles##########################-->
<targetname="combinecss"depends="init"description="Combinecommoncssfiles">
<echomessage="begintocombinethecssfilestoonefile."/>
<concatdestfile="${output.temp.dir}/combined_css.css"encoding="UTF-8"append="false">
<filesetdir="${commonCss.dir}">
<includename="*.css"/>
</fileset>
</concat>
<echomessage="combineend."/>
</target>
<!--#######################Combinethejsfiles##########################-->
<targetname="combinejs">
<echomessage="begintocombinethejsfilestoonefile."/>
<concatdestfile="${output.temp.dir}/all_source.js"encoding="utf-8"append="false">
<filesetdir="${commonJs.dir}">
<includename="*.js"/>
</fileset>
</concat>
<echomessage="combineend."/>
</target>
<!--#######################Compressthejsandcssfiles##########################-->
<targetname="compress"depends="combinecss,combinejs"description="Compress">
<echomessage="begintocompressthecssfile."/>
<taskdefname="yuicompress"classname="com.yahoo.platform.yui.compressor.YUICompressTask">
<classpath>
<pathrefid="yuiClasspath"/>
</classpath>
</taskdef>
<!--firstmethodcompressthecssfiles-->
<yuicompresslinebreak="10000000"warn="false"munge="yes"preserveallsemicolons="true"outputfolder="${output.dir}">
<filesetdir="${output.temp.dir}">
<includename="*.css"/>
</fileset>
</yuicompress>
<echomessage="compressthecssend."/>
<!--secondmethodcompressthejsfiles-->
<echomessage="begintocompressthejsfile."/>
<applyexecutable="java"parallel="false"failonerror="true">
<filesetdir="${output.temp.dir}"includes="all_source.js"/>
<argline="-jar"/>
<argpath="${lib}/yuicompressor-2.4.6.jar"/>
<argline="--charsetutf-8"/>
<argline="-o${output.dir}/combined_js.js"/>
<srcfile/>
</apply>
<echomessage="compressthejsend."/>
<deletedir="${output.temp.dir}"/>
</target>
</project>
@echooff
echo################################################
echo##########ToolCompressthejsandcss##########
echo################################################
echoPleasemakesureyourcssandjsinthecss'directoryandjs'directory.
echoIfsure,pleaseenteranybuttontocontinuethetool.
pause
callant-buildfilecompress.xmlcompress>build.log
echocompressend
pause
相关的文件我提供下载,感觉好的,就留言吧