使用YUI+Ant 实现JS CSS压缩今天研究了一下YUI yahoo开源框架,感觉很猛啊。
于是乎我做了一个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/
具体的相关代码如下:
xml代码#cssworkdircommonCss.dir=css#jsworkdircommonJs.dir=js#buildtempdiroutput.temp.dir=build#outputfilesinthedirectoryoutput.dir=${output.temp.dir}_output#environmentneedslibliblib=libBuild.xml代码<?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>Xml代码@echooffecho################################################echo##########ToolCompressthejsandcss##########echo################################################echoPleasemakesureyourcssandjsinthecss'directoryandjs'directory.echoIfsure,pleaseenteranybuttontocontinuethetool.pausecallant-buildfilecompress.xmlcompress>build.logechocompressendpause相关的文件我提供下载,感觉好的,就留言吧
YUICompressor.zip(1.5 MB)