使用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 相关文章推荐
php入门小知识
Mar 24 PHP
CodeIgniter php mvc框架 中国网站
May 26 PHP
PHP教程 变量定义
Oct 23 PHP
PHP与javascript实现变量交互的示例代码
Jul 23 PHP
基于PHP的简单采集数据入库程序
Jul 30 PHP
php中get_object_vars()方法用法实例
Feb 08 PHP
列举PHP的Yii 2框架的开发优势
Jul 03 PHP
全面了解PHP中的全局变量
Jun 17 PHP
PHP中如何判断exec函数执行成功?
Aug 04 PHP
php each 返回数组中当前的键值对并将数组指针向前移动一步实例
Nov 22 PHP
php实现的pdo公共类定义与用法示例
Jul 19 PHP
php和js实现根据子网掩码和ip计算子网功能示例
Nov 09 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
用mysql内存表来代替php session的类
2009/02/01 PHP
php中fgetcsv()函数用法实例
2014/11/28 PHP
PHP使用array_fill定义多维数组的方法
2015/03/18 PHP
利用php-cli和任务计划实现订单同步功能的方法
2017/05/03 PHP
JavaScript性能优化 创建文档碎片(document.createDocumentFragment)
2010/07/13 Javascript
jQuery操作checkbox选择(list/table)
2013/04/07 Javascript
JavaScript中使用Math.floor()方法对数字取整
2015/06/15 Javascript
15个常用的jquery代码片段
2015/12/19 Javascript
JavaScript函数柯里化详解
2016/04/29 Javascript
vue2.0 keep-alive最佳实践
2017/07/06 Javascript
基于Vue中点击组件外关闭组件的实现方法
2018/03/06 Javascript
vue之将echart封装为组件
2018/06/02 Javascript
解决layui中的form表单与button的点击事件冲突问题
2018/08/15 Javascript
Vue加载组件、动态加载组件的几种方式
2018/08/31 Javascript
jQuery+PHP实现上传裁剪图片
2020/06/29 jQuery
JavaScript静态作用域和动态作用域实例详解
2019/06/17 Javascript
python使用sorted函数对列表进行排序的方法
2015/04/04 Python
python如何使用unittest测试接口
2018/04/04 Python
python解决js文件utf-8编码乱码问题(推荐)
2018/05/02 Python
Python 实现域名解析为ip的方法
2019/02/14 Python
利用Python绘制有趣的万圣节南瓜怪效果
2019/10/31 Python
python使用yield压平嵌套字典的超简单方法
2019/11/02 Python
Python try except异常捕获机制原理解析
2020/04/18 Python
Python操作Excel把数据分给sheet
2020/05/20 Python
图片上传插件ImgUploadJS:用HTML5 File API 实现截图粘贴上传、拖拽上传
2016/01/20 HTML / CSS
NOTINO英国:在线购买美容和香水
2020/02/25 全球购物
大学生收银员求职信分享
2014/01/02 职场文书
2014年会演讲稿范文
2014/01/06 职场文书
人力资源部副职的竞聘演讲稿
2014/01/07 职场文书
工作失职检讨书范文
2014/01/16 职场文书
生物工程专业求职信
2014/09/03 职场文书
户籍证明模板
2014/09/28 职场文书
授权委托书协议书
2014/10/16 职场文书
西柏坡导游词
2015/02/05 职场文书
化妆品促销活动总结
2015/05/07 职场文书
python 开心网和豆瓣日记爬取的小爬虫
2021/05/29 Python