使用YUI+Ant 实现JS CSS压缩

今天研究了一下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/

具体的相关代码如下:

Xml代码  

  1. #css work dir
  2. commonCss.dir = css
  3. #js work dir
  4. commonJs.dir = js
  5. #build temp dir
  6. output.temp.dir = build
  7. #output files in the directory
  8. output.dir = ${output.temp.dir}_output
  9. #environment needs lib
  10. liblib = lib

Build.xml代码  

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="Compress CSS-JS" default="compress" basedir=".">
  3. <property file="bulid.properties" />
  4. <path id="yuiClasspath">
  5. <fileset dir="${lib}">
  6. <include name="*.*" />
  7. </fileset>
  8. </path>
  9. <!-- #######################Init the environment of the tool ##########################-->
  10. <target name="init">
  11. <echo message="begin to init the init" />
  12. <echo message="delete all reference files." />
  13. <delete dir="${output.dir}" />
  14. <echo message="delete end" />
  15. <echo message="make the reference files." />
  16. <mkdir dir="${output.dir}" />
  17. <mkdir dir="${output.temp.dir}" />
  18. <echo message="make end." />
  19. </target>
  20. <!-- #######################Combine the css files             ##########################-->
  21. <target name="combinecss" depends="init" description="Combine common css files">
  22. <echo message="begin to combine the css files to one file." />
  23. <concat destfile="${output.temp.dir}/combined_css.css" encoding="UTF-8" append="false">
  24. <fileset dir="${commonCss.dir}">
  25. <include name="*.css" />
  26. </fileset>
  27. </concat>
  28. <echo message="combine end." />
  29. </target>
  30. <!-- #######################Combine the js files             ##########################-->
  31. <target name="combinejs">
  32. <echo message="begin to combine the js files to one file." />
  33. <concat destfile="${output.temp.dir}/all_source.js" encoding="utf-8" append="false">
  34. <fileset dir="${commonJs.dir}">
  35. <include name="*.js" />
  36. </fileset>
  37. </concat>
  38. <echo message="combine end." />
  39. </target>
  40. <!-- #######################Compress the js and css files  ##########################-->
  41. <target name="compress" depends="combinecss,combinejs" description="Compress">
  42. <echo message="begin to compress the css file." />
  43. <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
  44. <classpath>
  45. <path refid="yuiClasspath" />
  46. </classpath>
  47. </taskdef>
  48. <!-- first method compress the css files -->
  49. <yuicompress linebreak="10000000" warn="false" munge="yes" preserveallsemicolons="true" outputfolder="${output.dir}">
  50. <fileset dir="${output.temp.dir}">
  51. <include name="*.css" />
  52. </fileset>
  53. </yuicompress>
  54. <echo message ="compress the css end." />
  55. <!-- second method compress the js files-->
  56. <echo message ="begin to compress the js file." />
  57. <apply executable="java" parallel="false" failonerror="true">
  58. <fileset dir="${output.temp.dir}" includes="all_source.js" />
  59. <arg line="-jar" />
  60. <arg path="${lib}/yuicompressor-2.4.6.jar" />
  61. <arg line="--charset utf-8" />
  62. <arg line="-o ${output.dir}/combined_js.js" />
  63. <srcfile />
  64. </apply>
  65. <echo message ="compress the js end." />
  66. <delete dir="${output.temp.dir}" />
  67. </target>
  68. </project>

Xml代码  

  1. @echo off
  2. echo ################################################
  3. echo ##########Tool Compress the js and css##########
  4. echo ################################################
  5. echo Please make sure your css and js in the css‘directory and js‘directory.
  6. echo If sure,please enter any button to continue the tool.
  7. pause
  8. call ant -buildfile compress.xml compress>build.log
  9. echo compress end
  10. pause

相关的文件我提供下载,感觉好的,就留言吧

时间: 2024-07-31 03:45:36

使用YUI+Ant 实现JS CSS压缩的相关文章

YUI+Ant 实现JS CSS压缩

今天研究了一下YUI yahoo开源框架,感觉很猛啊. 于是乎我做了一个YUI的ant实现,网上好多关于bat的实现,我就另辟蹊径,出个关于这个的ant实现,嘿嘿独一无二的文章,如果转载的话,其注明作者和网站 copyright:Mr.chen 好了具体操作如下: 官网: yuicompressor-2.4.6.jar 下载地址 http://yuilibrary.com/downloads/#yuicompressor YUIAnt.jar 下载地址 http://www.ubik-ingen

js css 压缩

合并和压缩JS.CSS文件 压缩JS,CSS文件需要引用如下组件: gulp-minify-css: 压缩css gulp-jshint: 检查js gulp-uglify: 压缩js gulp-concat: 合并文件 gulp-rename: 重命名文件 gulp-clean: 清空文件夹 gulp-notify:提示 安装组件项目目录,通过cd 进入项目的根目录,执行下边的npm安装组件 npm install gulp-minify-css gulp-jshint gulp-uglify

iis 发布asp.net mvc 网站时候js css 压缩问题,图片不加载问题

一.JS CSS 自动压缩问题 默认情况下mvc这个框架会把css,js文件压缩成一个js或者css文件,一会发现只有一个<link href="/Content/css?v=ji3nO1pdg6VLv3CVUWntxgZNf1zRciWDbm4YfW-y0RI1" rel="stylesheet"/>  和一个<script src="/bundles/modernizr?v=qVODBytEBVVePTNtSFXgRX0NCEjh9U

Asp.Net使用Yahoo.Yui.Compressor.dll压缩Js|Css

网上压缩css和js工具很多,但在我们的系统中总有特殊的地方.也许你会觉得用第三方的压缩工具很麻烦.我就遇到了这样问题,我不想在本地压缩,只想更新到服务器上去压缩,服务器压缩也不用备份之类的操作.于是我就想着自己实现压缩工具. 初步需求如下: 使用Yahoo.Yui.Compressor 2.0版本 只对网站目录下指定文件夹中css和js进行压缩 使用到了JQuery插件,所以有很多都是压缩过的js.所以对文件名称中保存min的不进行压缩 不需要备份文件 如在第一次访问文件时候进行压缩或应用程序

maven 配置合并压缩JS+CSS

1 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 2 <modelV

压缩 js/css 的工具

最近检测服务器,发现js/css文件都没有压缩过,动手解决此问题先. 本次压缩采用 yui compress (2.4.8) 压缩脚本: #!/bin/sh echo "###########################" echo "---------------------------" echo "begin to compress JS file." for file in `find . -name "*.js"

【JS代码压缩】使用YUI Compressor对js文件进行压缩处理

概述 在使用html5开发Hybird APP的时候,可能会引入大量的js包,另外对于一些核心的js文件,进行一些特殊的处理, 如压缩和加密就显得很重要了,YUI Compressor就是这样一个用于压缩js.css的工具(捂脸:其实我用它对代码进行 了压缩作为混淆处理的一种手段了),是采用Java开发的,因此运行的时候需要首先安装Java环境,安装完之后,运 行和配置都是比较简单的. 安装及使用 使用YUI Compressor之前必须先配置java环境,如何配置此处不说了. YUI Comp

flask前端优化:css/js/html压缩

1.先压缩再传输,可以减少传输的大小,减少传输时间,但是压缩需要时间,所以最终页面显示是快了还是慢了,需要比较 2.先看html压缩模块:pip install Flask-HTMLmin 压缩前:大小1.9M,完成时间1.20s 压缩后:大小1.3M,完成时间2.35s,反而时间更久了 2.再看css压缩和js压缩:pip install cssmin; pip install jsmin

gulp css html image js 合并压缩

安装node.js  npm  以及安装gulp等方法我就不在这里赘述了. 接下里我主要介绍的是Gulpfile文件里面的配置该如何书写. var gulp = require('gulp');//引入gulp组件 // 引入组件//在引入这些组件前你需要在你的项目里进行安装.举个栗子:组件中间用空格隔开.一定要先切换到你项目所在的目录 //npm install gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-d