今天研究了一下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/

具体的相关代码如下:

  1. #css work dir
  2. commonCss.dir = css
  3. #js work dir
  4. commonJs.dir = js
  5. #build temp dir
  6. output.temp.dir = build
  7. #output files in the directory
  8. output.dir = ${output.temp.dir}_output
  9. #environment needs lib
  10. liblib = lib
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="Compress CSS-JS" default="compress" basedir=".">
  3. <property file="bulid.properties" />
  4. <path id="yuiClasspath">
  5. <fileset dir="${lib}">
  6. <include name="*.*" />
  7. </fileset>
  8. </path>
  9. <!-- #######################Init the environment of the tool ##########################-->
  10. <target name="init">
  11. <echo message="begin to init the init" />
  12. <echo message="delete all reference files." />
  13. <delete dir="${output.dir}" />
  14. <echo message="delete end" />
  15. <echo message="make the reference files." />
  16. <mkdir dir="${output.dir}" />
  17. <mkdir dir="${output.temp.dir}" />
  18. <echo message="make end." />
  19. </target>
  20. <!-- #######################Combine the css files             ##########################-->
  21. <target name="combinecss" depends="init" description="Combine common css files">
  22. <echo message="begin to combine the css files to one file." />
  23. <concat destfile="${output.temp.dir}/combined_css.css" encoding="UTF-8" append="false">
  24. <fileset dir="${commonCss.dir}">
  25. <include name="*.css" />
  26. </fileset>
  27. </concat>
  28. <echo message="combine end." />
  29. </target>
  30. <!-- #######################Combine the js files             ##########################-->
  31. <target name="combinejs">
  32. <echo message="begin to combine the js files to one file." />
  33. <concat destfile="${output.temp.dir}/all_source.js" encoding="utf-8" append="false">
  34. <fileset dir="${commonJs.dir}">
  35. <include name="*.js" />
  36. </fileset>
  37. </concat>
  38. <echo message="combine end." />
  39. </target>
  40. <!-- #######################Compress the js and css files  ##########################-->
  41. <target name="compress" depends="combinecss,combinejs" description="Compress">
  42. <echo message="begin to compress the css file." />
  43. <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
  44. <classpath>
  45. <path refid="yuiClasspath" />
  46. </classpath>
  47. </taskdef>
  48. <!-- first method compress the css files -->
  49. <yuicompress linebreak="10000000" warn="false" munge="yes" preserveallsemicolons="true" outputfolder="${output.dir}">
  50. <fileset dir="${output.temp.dir}">
  51. <include name="*.css" />
  52. </fileset>
  53. </yuicompress>
  54. <echo message ="compress the css end." />
  55. <!-- second method compress the js files-->
  56. <echo message ="begin to compress the js file." />
  57. <apply executable="java" parallel="false" failonerror="true">
  58. <fileset dir="${output.temp.dir}" includes="all_source.js" />
  59. <arg line="-jar" />
  60. <arg path="${lib}/yuicompressor-2.4.6.jar" />
  61. <arg line="--charset utf-8" />
  62. <arg line="-o ${output.dir}/combined_js.js" />
  63. <srcfile />
  64. </apply>
  65. <echo message ="compress the js end." />
  66. <delete dir="${output.temp.dir}" />
  67. </target>
  68. </project>
  1. @echo off
  2. echo ################################################
  3. echo ##########Tool Compress the js and css##########
  4. echo ################################################
  5. echo Please make sure your css and js in the css'directory and js'directory.
  6. echo If sure,please enter any button to continue the tool.
  7. pause
  8. call ant -buildfile compress.xml compress>build.log
  9. echo compress end
  10. pause

相关的文件我提供下载,感觉好的,就留言吧

04-25 12:23
查看更多