yuicompressor压缩js的ant脚本

yuicompressor压缩js的ant脚本<?xmlversion="1.0"encoding="UTF-8"?> <!–对指定目录下的所有js进行压缩,放入指定位置–> <projectname="jsbuild"default="build">    <propertyname="web.dir"location=&quo

大家好,又见面了,我是你们的朋友全栈君。

<?xml version=”1.0″ encoding=”UTF-8″?> 
<!– 对指定目录下的所有js进行压缩,放入指定位置 –> 
<project name=”jsbuild” default=”build”> 
    <property name=”web.dir” location=”WebRoot” /> 
    <property name=”yuicompressor.jar” location=”${web.dir}/WEB-INF/lib/yuicompressor-2.4.2.jar” /> 
 
    <!– 得到当前日期 –> 
    <tstamp> 
        <format property=”now.date” pattern=”yyyy-MM-dd” locale=”zh” /> 
    </tstamp> 
      
    <!– 要压缩的js源文件所在文件夹,这个文件里的所有js将被压缩 –> 
    <property name=”source.dir” location=”${web.dir}/js”/> 
          
    <!– 目标目录,压缩后的js文件放在哪个目录下 –> 
    <property name=”dest.dir” location=”${web.dir}/js/compress”/> 
      
    <!– 压缩过程中的临时目录 –> 
    <property name=”temp” location=”${web.dir}/tmp/${now.date}”/> 
      
    <!– 压缩完成后, copy要压缩文件至目标目录 –> 
    <target name=”build” depends=”js.compress”> 
     <!–
     <echo message=”压缩完成后, 拷贝${temp}/*.js至${source.dir}目录,并删除tmp目录”>[开始]</echo>
     <copy todir=”${source.dir}” overwrite=”true”>
      <fileset dir=”${temp}” includes=”*.js” />
     </copy>
     <delete dir=”${web.dir}/tmp”/>
     <echo message=”压缩完成后, 拷贝${temp}/*.js至${source.dir}目录,并删除tmp目录”>[结束]</echo>
     –>
        <!– <copy file=”${temp}/compress-all-pack.js” tofile=”${dest.dir}/compress-all-pack.js” overwrite=”true” failοnerrοr=”false”/> 
        <echo message=”压缩完成后, 拷贝${temp}/compress-all-pack.js至目标目录”></echo> –> 
    </target> 
      
    <!– YUI Compress 压缩合并操作–>   
      <target name=”js.compress” depends=”createTemp”>     
          <!– 循环压缩文件 –>    
          <echo message=”循环压缩${temp}所有js文件”>[开始]</echo>    
          <apply executable=”java” parallel=”false” failοnerrοr=”true”>      
              <fileset dir=”${source.dir}” includes=”*.js” /> <!– 源文件及所在目录, 指定下面要循环文件 –>    
              <arg line=”-jar” />       
              <arg path=”${yuicompressor.jar}” />       
              <arg line=”–charset utf-8″ />     
              <srcfile />    
              <arg line=”-o” />    
              <targetfile />       
              <mapper type=”glob” from=”*.js” to=”${temp}/*.js” />    
          </apply>     
          <echo message=”循环压缩${temp}所有js文件”>[结束]</echo>    
              
          <!– 连接文件至目标目录 fixlastline=”true” 每个文件占一行 –>    
          <echo message=”将${temp}目录下所有js压缩成一个文件至${temp}/compress-all-pack.js”>[开始]</echo>    
          <concat destfile=”${dest.dir}/compress-all-pack.js” fixlastline=”true” encoding=”UTF-8″>    
              <fileset dir=”${temp}”>    
                  <include name=”**.js” />    
                  <exclude name=”*.css”/> <!– 排除 –>    
              </fileset>    
          </concat>    
          <echo message=”将${temp}目录下所有js压缩成一个文件至${dest.dir}/compress-all-pack.js”>[结束]</echo>    
      </target>       
          
      <!– 创建临时目录 –>    
      <target name=”createTemp” description=”创建临时目录”>    
         <delete dir=”${temp}”/>  
          <mkdir dir=”${temp}”/>    
          <echo>创建临时目录${temp}</echo>    
      </target>    
  </project> 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/161240.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号