使用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调用google接口生成二维码示例
Apr 28 PHP
PHP实现通过中文字符比率来判断垃圾评论的方法
Oct 20 PHP
laravel 4安装及入门图文教程
Oct 29 PHP
thinkPHP使用post方式查询时分页失效的解决方法
Dec 09 PHP
简单介绍PHP非阻塞模式
Mar 03 PHP
实例讲解如何在PHP的Yii框架中进行错误和异常处理
Mar 17 PHP
php自定义函数实现二维数组排序功能
Jul 20 PHP
PHP简单创建压缩图的方法
Aug 24 PHP
php实现websocket实时消息推送
Mar 30 PHP
PHP切割汉字的常用方法实例总结
Apr 27 PHP
对laravel的csrf 防御机制详解,及form中csrf_token()的存在介绍
Oct 24 PHP
PHP7 新增功能
Mar 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
提升PHP执行速度全攻略(下)
2006/10/09 PHP
解析如何用php screw加密php源代码
2013/06/20 PHP
php微信公众号开发之校园图书馆
2018/10/20 PHP
JavaScript 变量命名规则
2009/09/23 Javascript
jQuery的运行机制和设计理念分析
2011/04/05 Javascript
javascript实现checkBox的全选,反选与赋值
2015/03/12 Javascript
60行js代码实现俄罗斯方块
2015/03/31 Javascript
JavaScript常用函数工具集:lao-utils
2016/03/01 Javascript
jQuery实现侧浮窗与中浮窗切换效果的方法
2016/09/05 Javascript
整理关于Bootstrap列表组的慕课笔记
2017/03/29 Javascript
用Vue-cli搭建的项目中引入css报错的原因分析
2017/07/20 Javascript
react native与webview通信的示例代码
2017/09/25 Javascript
原生js实现form表单序列化的方法
2018/08/02 Javascript
vueJs实现DOM加载完之后自动下拉到底部的实例代码
2018/08/31 Javascript
ES6使用export和import实现模块化的方法
2018/09/10 Javascript
微信小程序适配iphoneX的实现方法
2018/09/18 Javascript
详解如何使用router-link对象方式传递参数?
2019/05/02 Javascript
Vue混入mixins滚动触底的方法
2019/11/22 Javascript
python实现ipsec开权限实例
2014/11/11 Python
在Windows中设置Python环境变量的实例讲解
2018/04/28 Python
python处理数据,存进hive表的方法
2018/07/04 Python
用python实现k近邻算法的示例代码
2018/09/06 Python
Pycharm新手教程(只需要看这篇就够了)
2019/06/18 Python
Django 数据库同步操作技巧详解
2019/07/19 Python
解决IDEA 的 plugins 搜不到任何的插件问题
2020/05/04 Python
AmazeUI 等分网格的实现示例
2020/08/25 HTML / CSS
域名注册、建站工具、网页主机、SSL证书:Dynadot
2017/01/06 全球购物
总经理岗位职责
2013/11/09 职场文书
中秋节超市促销方案
2014/01/30 职场文书
创业融资计划书
2014/04/25 职场文书
超市七夕促销活动方案
2014/08/28 职场文书
社区元宵节活动总结
2015/02/06 职场文书
巴黎圣母院读书笔记
2015/06/26 职场文书
MySql学习笔记之事务隔离级别详解
2021/05/12 MySQL
MySQL 自定义变量的概念及特点
2021/05/13 MySQL
Python3 类型标注支持操作
2021/06/02 Python