使用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 项目的方法
Jan 02 PHP
PHP写入WRITE编码为UTF8的文件的实现代码
Jul 07 PHP
php打开文件fopen函数的使用说明
Jul 05 PHP
PHP连接MySQL查询结果中文显示乱码解决方法
Oct 25 PHP
ThinkPHP表单自动验证实例
Oct 13 PHP
php生成图片验证码
Jun 09 PHP
一个PHP实现的轻量级简单爬虫
Jul 08 PHP
使用PHP实现下载CSS文件中的图片
Dec 06 PHP
PHP定时任务获取微信access_token的方法
Oct 10 PHP
详解Yii2.0 rules验证规则集合
Mar 21 PHP
Laravel 批量更新多条数据的示例
Nov 27 PHP
php删除一个路径下的所有文件夹和文件的方法
Feb 07 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
优化NFR之一 --MSSQL Hello Buffer Overflow
2006/10/09 PHP
php 404错误页面实现代码
2009/06/22 PHP
PHP字符串中特殊符号的过滤方法介绍
2014/02/18 PHP
百度工程师讲PHP函数的实现原理及性能分析(二)
2015/05/13 PHP
ThinkPHP进程计数类Process用法实例详解
2015/09/25 PHP
PHP微信支付结果通知与回调策略分析
2019/01/10 PHP
用javascript实现画板的代码
2007/09/05 Javascript
jQuery弹出层插件简化版代码下载
2008/10/16 Javascript
jquery控制listbox中项的移动并排序
2009/11/12 Javascript
JS获取整个页面文档的实现代码
2011/12/15 Javascript
webapp框架AngularUI的demo改造之路
2014/12/21 Javascript
JS实现仿Windows7风格的网页右键菜单效果代码
2015/09/11 Javascript
Vue的MVVM实现方法
2017/08/16 Javascript
vue.js 嵌套循环、if判断、动态删除的实例
2018/03/07 Javascript
vue 界面刷新数据被清除 localStorage的使用详解
2018/09/16 Javascript
bootstrap 日期控件 datepicker被弹出框dialog覆盖的解决办法
2019/07/09 Javascript
js模拟F11页面全屏显示
2019/09/17 Javascript
vue项目页面嵌入代码块vue-prism-editor的实现
2020/10/30 Javascript
[01:19:54]DOTA2上海特级锦标赛主赛事日 - 2 败者组第二轮#1Alliance VS EHOME
2016/03/03 DOTA
Python爬取读者并制作成PDF
2015/03/10 Python
python使用urlparse分析网址中域名的方法
2015/04/15 Python
在PyCharm环境中使用Jupyter Notebook的两种方法总结
2018/05/24 Python
使用Python在Windows下获取USB PID&amp;VID的方法
2019/07/02 Python
Python多线程爬取豆瓣影评API接口
2019/10/22 Python
Python使用OpenPyXL处理Excel表格
2020/07/02 Python
OpenCV利用python来实现图像的直方图均衡化
2020/10/21 Python
python-jwt用户认证食用教学的实现方法
2021/01/19 Python
Django与AJAX实现网页动态数据显示的示例代码
2021/02/24 Python
英国可持续奢侈品包包品牌:Elvis & Kresse
2018/08/05 全球购物
英国蛋糕装饰用品一站式商店:Craft Company
2019/03/18 全球购物
adidas马来西亚官网:adidas MY
2020/09/12 全球购物
简历自我评价怎么写呢?
2014/01/06 职场文书
学习社交礼仪心得体会
2016/01/22 职场文书
python学习之panda数据分析核心支持库
2021/05/07 Python
CSS作用域(样式分割)的使用汇总
2021/11/07 HTML / CSS
九大龙王魂骨,山龙王留下躯干骨,榜首死的最憋屈(被捏碎)
2022/03/18 国漫