使用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 17 PHP
LotusPhp笔记之:基于ObjectUtil组件的使用分析
May 06 PHP
C#使用PHP服务端的Web Service通信实例
Apr 08 PHP
PHP使用Alexa API获取网站的Alexa排名例子
Jun 12 PHP
Yii框架调试心得--在页面输出执行sql语句
Dec 25 PHP
PHP实现过滤掉非汉字字符只保留中文字符
Jun 04 PHP
浅谈PDO的rowCount函数
Jun 18 PHP
[原创]php简单隔行变色功能实现代码
Jul 09 PHP
PHP Mysqli 常用代码集合
Nov 12 PHP
php+Memcached实现简单留言板功能示例
Feb 15 PHP
PHP使用星号替代用户名手机和邮箱的实现代码
Feb 07 PHP
php使用pthreads v3多线程实现抓取新浪新闻信息操作示例
Feb 21 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
基于文本的留言簿
2006/10/09 PHP
php 数组随机取值的简单实例
2016/05/23 PHP
laravel框架中视图的基本使用方法分析
2019/11/23 PHP
Extjs中TabPane如何嵌套在其他网页中实现思路及代码
2013/01/27 Javascript
基于jquery实现的文字淡入淡出效果
2013/11/14 Javascript
原生js实现类似弹窗抖动效果
2015/04/02 Javascript
用file标签实现多图文件上传预览
2017/02/14 Javascript
详解在vue-cli项目中使用mockjs(请求数据删除数据)
2017/10/23 Javascript
使用vuex解决刷新页面state数据消失的问题记录
2019/05/08 Javascript
VueJS实现用户管理系统
2020/05/29 Javascript
JavaScript字符串转数字的简单实现方法
2020/11/27 Javascript
[10:18]2018DOTA2国际邀请赛寻真——找回自信的TNCPredator
2018/08/13 DOTA
Pyramid添加Middleware的方法实例
2013/11/27 Python
Python中关于字符串对象的一些基础知识
2015/04/08 Python
对django中foreignkey的简单使用详解
2019/07/28 Python
Python导入模块包原理及相关注意事项
2020/03/25 Python
django为Form生成的label标签添加class方式
2020/05/20 Python
解决python调用自己文件函数/执行函数找不到包问题
2020/06/01 Python
pycharm 代码自动补全的实现方法(图文)
2020/09/18 Python
css3学习之2D转换功能详解
2016/12/23 HTML / CSS
纯CSS3实现漂亮的input输入框动画样式库(Text input love)
2018/12/29 HTML / CSS
HTML5本地存储localStorage、sessionStorage基本用法、遍历操作、异常处理等
2014/05/08 HTML / CSS
canvas像素点操作之视频绿幕抠图
2018/09/11 HTML / CSS
Puritan’s Pride(普丽普莱)官方网站:美国最大最全的保健品公司之一
2016/10/23 全球购物
乌克兰鞋类购物网站:Eobuv.com.ua
2020/11/28 全球购物
农民工创业典型事迹
2014/01/25 职场文书
大二法英学生职业生涯规划范文
2014/02/27 职场文书
竞聘书模板
2014/03/31 职场文书
员工趣味活动方案
2014/08/27 职场文书
个人委托书范本
2014/09/13 职场文书
2015年大学生党员承诺书
2015/04/27 职场文书
辞职信格式范文
2015/05/13 职场文书
2016教师学习党章心得体会
2016/01/15 职场文书
读《推着妈妈去旅行》有感1500字
2019/10/15 职场文书
励志正能量20句:送给所有为梦想拼搏的人
2019/11/11 职场文书
GPU服务器的多用户配置方法
2022/07/07 Servers