使用YUI+Ant 实现JS CSS压缩
2015-01-24信息快讯网
YUI库是一组工具和控件,它们用JavaScript写成, 为的是用DOM 脚本,DHTML和AJAX等技术创建丰富的网页交互式应用程序。YUI 基于BSD协议,对所有的使用方式都是免费的。YUI 项目包括YUI 库和两个创建时工具:YUI Compressor (压缩)和YUI Doc(JavaScripts代码的文档引擎)
今天研究了一下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中JSON的使用与转换
php5.4以下版本json不支持不转义内容中文的解决方法
php正则匹配html中带class的div并选取其中内容的方法
PHP针对JSON操作实例分析
php的sso单点登录实现方法
js+php实现静态页面实时调用用户登陆状态的方法
php读取mssql的ntext字段返回值为空的解决方法
php查询mssql出现乱码的解决方法
VPS中使用LNMP安装WordPress教程
PHP中require和include路径问题详解
PHP采集静态页面并把页面css,img,js保存的方法
php获取CSS文件中图片地址并下载到本地的方法
ThinkPHP模版中导入CSS和JS文件的方法
php实现的css文件背景图片下载器代码
php实现压缩多个CSS与JS文件的方法
Yii查询生成器(Query Builder)用法实例教程
Fedora下安装php Redis扩展笔记
在Ubuntu 14.04上部署 PHP 环境及 WordPress
PHP处理Json字符串解码返回NULL的解决方法
PHP中cookie和session的区别实例分析
PHP实现利用MySQL保存session的方法
PHP函数http_build_query使用详解
PHP中使用json数据格式定义字面量对象的方法
PHP针对常规模板引擎中与CSS/JSON冲突的解决方法
php解析json数据实例
php中Session的生成机制、回收机制和存储机制探究
PHP JSON出错:Cannot use object of type stdClass as array解决方法
php ci框架中加载css和js文件失败的原因及解决方法
函数中使用require_once问题深入探讨 优雅的配置文件定义方法推荐
PHP根据传入参数合并多个JS和CSS文件的简单实现
PHP小技巧之JS和CSS优化工具Minify的使用方法
yii框架builder、update、delete使用方法
PHP包含文件函数include、include_once、require、require_once区别总结
easyui的tabs update正确用法分享