使用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 chr() ord()中文截取乱码问题解决方法
Sep 08 PHP
php实现jQuery扩展函数
Oct 30 PHP
php在服务器执行exec命令失败的解决方法
Mar 03 PHP
php curl 伪造IP来源的实例代码
Nov 01 PHP
PHP设计模式之结构模式的深入解析
Jun 13 PHP
Yii中render和renderPartial的区别
Sep 03 PHP
php中base64_decode与base64_encode加密解密函数实例
Nov 24 PHP
Laravel中使用阿里云OSS Composer包分享
Feb 10 PHP
php实现简单的MVC框架实例
Sep 23 PHP
php将从数据库中获得的数据转换成json格式并输出的方法
Aug 21 PHP
PHP实现数据四舍五入的方法小结【4种方法】
Mar 27 PHP
在Laravel 中实现是否关注的示例
Oct 22 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连接Oracle for NT 远程数据库
2006/10/09 PHP
PHP生成随机用户名和密码的实现代码
2013/02/27 PHP
PHP Yaf框架的简单安装使用教程(推荐)
2016/06/08 PHP
PHP实现模拟http请求的方法分析
2017/12/20 PHP
PHP session垃圾回收机制实例分析
2019/06/28 PHP
Javascript的IE和Firefox兼容性汇编(zz)
2007/02/02 Javascript
javascript中的prototype属性使用说明(函数功能扩展)
2010/08/16 Javascript
js的alert样式如何更改如背景颜色
2014/01/22 Javascript
JS右下角广告窗口代码(可收缩、展开及关闭)
2015/09/04 Javascript
jquery自动补齐功能插件flexselect用法示例
2016/08/06 Javascript
JavaScript页面实时显示当前时间实例代码
2016/10/23 Javascript
利用transition实现文字上下抖动的效果
2017/01/21 Javascript
vue中如何创建多个ueditor实例教程
2017/11/14 Javascript
antd日期选择器禁止选择当天之前的时间操作
2020/10/29 Javascript
使用PYTHON接收多播数据的代码
2012/03/01 Python
python统计一个文本中重复行数的方法
2014/11/19 Python
详解Python中for循环的使用方法
2015/05/14 Python
对numpy中数组元素的统一赋值实例
2018/04/04 Python
python实现俄罗斯方块
2018/06/26 Python
Python图像处理之图像的缩放、旋转与翻转实现方法示例
2019/01/04 Python
python实现控制台打印的方法
2019/01/12 Python
浅谈python str.format与制表符\t关于中文对齐的细节问题
2019/01/14 Python
python实现的接收邮件功能示例【基于网易POP3服务器】
2019/09/11 Python
pytorch标签转onehot形式实例
2020/01/02 Python
你不知道的葡萄干处理法、橙蜜处理法、二氧化碳酵母法
2021/03/17 冲泡冲煮
YSL Beauty加拿大官方商城:圣罗兰美妆加拿大
2017/05/15 全球购物
亚历山大·王官网:Alexander Wang
2017/06/23 全球购物
行政前台岗位职责
2013/12/04 职场文书
战友聚会邀请函
2014/01/18 职场文书
环保倡议书
2014/04/14 职场文书
安全演讲稿大全
2014/05/09 职场文书
办理护照工作证明
2014/10/10 职场文书
银行求职信范文怎么写
2015/03/20 职场文书
中标通知书格式
2015/04/17 职场文书
警示教育片观后感
2015/06/17 职场文书
Vue OpenLayer测距功能的实现
2022/04/20 Vue.js