使用YUI+Ant 实现JS CSS压缩


Posted in PHP onSeptember 02, 2014

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

具体的相关代码如下:

#css work dir 
commonCss.dir = css 
 
#js work dir 
commonJs.dir = js 
 
#build temp dir  
output.temp.dir = build 
 
#output files in the directory 
output.dir = ${output.temp.dir}_output 
 
#environment needs lib 
liblib = lib 
 
<?xml version="1.0" encoding="UTF-8"?> 
 
<project name="Compress CSS-JS" default="compress" basedir="."> 
 
  <property file="bulid.properties" /> 
 
  <path id="yuiClasspath"> 
    <fileset dir="${lib}"> 
      <include name="*.*" /> 
    </fileset> 
  </path> 
 
  <!-- #######################Init the environment of the tool ##########################--> 
  <target name="init"> 
    <echo message="begin to init the init" /> 
    <echo message="delete all reference files." /> 
    <delete dir="${output.dir}" /> 
    <echo message="delete end" /> 
    <echo message="make the reference files." /> 
    <mkdir dir="${output.dir}" /> 
    <mkdir dir="${output.temp.dir}" /> 
    <echo message="make end." /> 
  </target> 
 
  <!-- #######################Combine the css files       ##########################--> 
  <target name="combinecss" depends="init" description="Combine common css files"> 
    <echo message="begin to combine the css files to one file." /> 
    <concat destfile="${output.temp.dir}/combined_css.css" encoding="UTF-8" append="false"> 
      <fileset dir="${commonCss.dir}"> 
        <include name="*.css" /> 
      </fileset> 
    </concat> 
    <echo message="combine end." /> 
  </target> 
 
  <!-- #######################Combine the js files       ##########################--> 
  <target name="combinejs"> 
    <echo message="begin to combine the js files to one file." /> 
    <concat destfile="${output.temp.dir}/all_source.js" encoding="utf-8" append="false"> 
      <fileset dir="${commonJs.dir}"> 
        <include name="*.js" /> 
      </fileset> 
    </concat> 
    <echo message="combine end." /> 
  </target> 
 
  <!-- #######################Compress the js and css files ##########################--> 
  <target name="compress" depends="combinecss,combinejs" description="Compress"> 
    <echo message="begin to compress the css file." /> 
    <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask"> 
      <classpath> 
        <path refid="yuiClasspath" /> 
      </classpath> 
    </taskdef> 
    <!-- first method compress the css files --> 
    <yuicompress linebreak="10000000" warn="false" munge="yes" preserveallsemicolons="true" outputfolder="${output.dir}"> 
      <fileset dir="${output.temp.dir}"> 
        <include name="*.css" /> 
      </fileset> 
    </yuicompress> 
    <echo message ="compress the css end." /> 
    <!-- second method compress the js files--> 
    <echo message ="begin to compress the js file." /> 
    <apply executable="java" parallel="false" failonerror="true"> 
      <fileset dir="${output.temp.dir}" includes="all_source.js" /> 
      <arg line="-jar" /> 
      <arg path="${lib}/yuicompressor-2.4.6.jar" /> 
      <arg line="--charset utf-8" /> 
      <arg line="-o ${output.dir}/combined_js.js" /> 
      <srcfile /> 
    </apply> 
    <echo message ="compress the js end." /> 
    <delete dir="${output.temp.dir}" /> 
  </target> 
 
</project> 
 
@echo off 
echo ################################################ 
echo ##########Tool Compress the js and css########## 
echo ################################################ 
echo Please make sure your css and js in the css'directory and js'directory. 
echo If sure,please enter any button to continue the tool. 
pause 
call ant -buildfile compress.xml compress>build.log 
echo compress end  
pause

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

PHP 相关文章推荐
第五节 克隆 [5]
Oct 09 PHP
PHP+DBM的同学录程序(2)
Oct 09 PHP
php 什么是PEAR?
Mar 19 PHP
php数组一对一替换实现代码
Aug 31 PHP
深入PHP异步执行的详解
Jun 03 PHP
php强制文件下载而非在浏览器打开的自定义函数分享
May 08 PHP
php生成excel列名超过26列大于Z时的解决方法
Dec 29 PHP
PHP解析RSS的方法
Mar 05 PHP
一段实用的php验证码函数
May 19 PHP
php mysql like 实现多关键词搜索的方法
Oct 29 PHP
PHP删除数组中指定下标的元素方法
Feb 03 PHP
PHP控制循环操作的时间
Apr 01 PHP
在Ubuntu 14.04上部署 PHP 环境及 WordPress
Sep 02 #PHP
PHP高级编程实例:编写守护进程
Sep 02 #PHP
php输入流php://input使用浅析
Sep 02 #PHP
php获取URL中带#号等特殊符号参数的解决方法
Sep 02 #PHP
PHP中提问频率最高的11个面试题和答案
Sep 02 #PHP
PHP处理Json字符串解码返回NULL的解决方法
Sep 01 #PHP
PHP实现更新中间关联表数据的两种方法
Sep 01 #PHP
You might like
PHP中文URL编解码(urlencode()rawurlencode()
2010/07/03 PHP
php上传文件中文文件名乱码的解决方法
2013/11/01 PHP
IIS6.0 开启Gzip方法及PHP Gzip函数分享
2014/06/08 PHP
php返回json数据函数实例
2014/10/09 PHP
PHP通过API获取手机号码归属地
2015/05/28 PHP
CodeIgniter针对lighttpd服务器URL重写的方法
2015/06/10 PHP
php mysql获取表字段名称和字段信息的三种方法
2016/11/13 PHP
php注册系统和使用Xajax即时验证用户名是否被占用
2017/08/31 PHP
csdn 博客中实现运行代码功能实现
2009/08/29 Javascript
js文件中调用js的实现方法小结
2009/10/23 Javascript
基于jQuery的让非HTML5浏览器支持placeholder属性的代码
2011/05/24 Javascript
jquery设置元素的readonly和disabled的写法
2013/09/22 Javascript
javascript引用赋值(地址传值)用法实例
2015/01/13 Javascript
jQuery实现可展开折叠的导航效果示例
2016/09/12 Javascript
在React中如何优雅的处理事件响应详解
2017/07/24 Javascript
面包屑导航详解
2017/12/07 Javascript
vue使用axios实现文件上传进度的实时更新详解
2017/12/20 Javascript
详解ES6语法之可迭代协议和迭代器协议
2018/01/13 Javascript
vue使用vuex实现首页导航切换不同路由的方法
2019/05/08 Javascript
基于JavaScript实现十五拼图代码实例
2020/04/26 Javascript
vue中实现图片压缩 file文件的方法
2020/05/28 Javascript
vue实现移动端H5数字键盘组件使用详解
2020/08/25 Javascript
Python实现各种排序算法的代码示例总结
2015/12/11 Python
Python 查看文件的读写权限方法
2018/01/23 Python
对python字典过滤条件的实例详解
2019/01/22 Python
介绍一款python类型检查工具pyright(推荐)
2019/07/03 Python
python获取当前文件路径以及父文件路径的方法
2019/07/10 Python
详解python路径拼接os.path.join()函数的用法
2019/10/09 Python
pygame实现俄罗斯方块游戏(对战篇1)
2019/10/29 Python
使用python动态生成波形曲线的实现
2019/12/04 Python
python GUI库图形界面开发之PyQt5控件数据拖曳Drag与Drop详细使用方法与实例
2020/02/27 Python
Mytheresa美国官网:德国知名的女性奢侈品电商
2017/05/27 全球购物
校庆筹备方案
2014/03/30 职场文书
法定代表人授权委托书范文
2014/09/22 职场文书
群众路线党员个人整改措施
2014/10/27 职场文书
2016年植树节红领巾广播稿
2015/12/17 职场文书