使用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中foreach循环中使用引用要注意的地方
Jan 02 PHP
PHP中调用ASP.NET的WebService的代码
Apr 22 PHP
PHP 利用AJAX获取网页并输出的实现代码(Zjmainstay)
Aug 31 PHP
PHP获取指定函数定义在哪个文件中以及其所在的行号实例
May 08 PHP
PHP实现数字补零功能的2个函数介绍
May 12 PHP
以文件形式缓存php变量的方法
Jun 26 PHP
php文件上传你必须知道的几点
Oct 20 PHP
php+ajax实现无刷新数据分页的办法
Nov 02 PHP
Symfony2使用第三方库Upload制作图片上传实例详解
Feb 04 PHP
9个比较实用的php代码片段
Mar 15 PHP
Zend Framework入门之环境配置及第一个Hello World示例(附demo源码下载)
Mar 21 PHP
laravel实现于语言包的完美切换方法
Sep 29 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/12/06 PHP
php smarty 二级分类代码和模版循环例子
2011/06/16 PHP
JavaScript 学习笔记(四)
2009/12/31 Javascript
从零开始学习jQuery (二) 万能的选择器
2010/10/01 Javascript
JavaScript设计模式之单例模式实例
2014/09/24 Javascript
28个常用JavaScript方法集锦
2015/01/14 Javascript
使用Angular和Nodejs、socket.io搭建聊天室及多人聊天室
2015/08/21 NodeJs
javascript字符串函数汇总
2015/12/06 Javascript
javascript每日必学之封装
2016/02/23 Javascript
javascript数组去重方法分析
2016/12/15 Javascript
浅谈Angular2 模块懒加载的方法
2017/10/04 Javascript
在vue项目中引用Iview的方法
2018/09/14 Javascript
[02:00]DOTA2英雄COSPLAY闹市街头巡游助威2015国际邀请赛
2015/08/02 DOTA
[55:48]VGJ.S vs TNC Supermajor 败者组 BO3 第二场 6.6
2018/06/07 DOTA
python使用socket向客户端发送数据的方法
2015/04/29 Python
python连接MySQL数据库实例分析
2015/05/12 Python
分享一下如何编写高效且优雅的 Python 代码
2017/09/07 Python
python爬虫headers设置后无效的解决方法
2017/10/21 Python
python获取指定字符串中重复模式最高的字符串方法
2018/06/29 Python
使用Python实现将list中的每一项的首字母大写
2019/06/11 Python
python 计算数据偏差和峰度的方法
2019/06/29 Python
Python通过4种方式实现进程数据通信
2020/03/12 Python
查看已安装tensorflow版本的方法示例
2020/04/19 Python
python list的index()和find()的实现
2020/11/16 Python
Python运算符+与+=的方法实例
2021/02/18 Python
详解css3 flex弹性盒自动铺满写法
2020/09/17 HTML / CSS
波兰家居和花园家具专家:4Home
2019/05/26 全球购物
Yankee Candle官网:美国最畅销蜡烛品牌之一
2020/01/05 全球购物
英国家具、照明、家居用品网上商店:Wayfair.co.uk
2020/02/13 全球购物
大学军训感言
2014/01/10 职场文书
企业内部培训方案
2014/02/04 职场文书
教师产假请假条
2014/04/10 职场文书
兴趣小组活动总结
2014/05/05 职场文书
经典团队口号大全
2014/06/21 职场文书
2015年公司行政后勤工作总结
2015/05/20 职场文书
matplotlib之pyplot模块实现添加子图subplot的使用
2021/04/25 Python