当前位置: 代码迷 >> Web前端 >> YUI Compressor 施用
  详细解决方案

YUI Compressor 施用

热度:550   发布时间:2012-11-12 12:31:57.0
YUI Compressor 使用

最近项目需求,要压缩js,文件就学习了YUI Compressor。

下载:http://yuilibrary.com/downloads/#yuicompressor。 最新的是2.4.6。前提是要安装jdk,就不废话了。

下载下来后解压。找到 yuicompressor-2.4.6\build\yuicompressor-2.4.6.jar

这个就是要运行的jar.

打开cmd.输入(我要压缩的文件放到了e盘符根目录。)

C:\Documents and Settings\Administrator>java -jar E:\yuicompressor-2.4.6\yuicomp
ressor-2.4.6\build\yuicompressor-2.4.6.jar? --preserve-semi?? -o? E:\outputfile.js ? ? E:\inputfile.js

?

好了,在e盘目录下就生成了一个压缩好的文件。参数详见下面。

?

-----------------------------------------------------

Usage: java -jar yuicompressor-x.y.z.jar [options] [input file]

Global Options
? -h, --help??????????????? Displays this information
? --type <js|css>?????????? Specifies the type of the input file
? --charset <charset>?????? Read the input file using <charset>
? --line-break <column>???? Insert a line break after the specified column numbr
? -v, --verbose???????????? Display informational messages and warnings
? -o <file>???????????????? Place the output into <file>. Defaults to stdout.
??????????????????????????? Multiple files can be processed using the following
syntax:
??????????????????????????? java -jar yuicompressor.jar -o '.css$:-min.css' *.c
s
??????????????????????????? java -jar yuicompressor.jar -o '.js$:-min.js' *.js

JavaScript Options
? --nomunge???????????????? Minify only, do not obfuscate
? --preserve-semi?????????? Preserve all semicolons
? --disable-optimizations?? Disable all micro optimizations

If no input file is specified, it defaults to stdin. In this case, the 'type'
option is required. Otherwise, the 'type' option is required only if the input
file extension is neither 'js' nor 'css'.

------------------------------------------------------

语法: java -jar yuicompressor-x.y.z.jar [options] [input file] 通用参数:
??? -h, --help???????????????? 显示帮助信息
?? --type <js|css>??????????? 指定输入文件的文件类型
?? --charset <charset>??????? 指定读取输入文件使用的编码
?? --line-break <column>????? 在指定的列后插入一个 line-bread 符
?? -v, --verbose????????????? 显示info和warn级别的信息
?? -o <file>????????????????? 指定输出文件。默认输出是控制台。

JavaScript专用参数:
???? --nomunge????????????????? 只压缩, 不对局部变量进行混淆。
?? --preserve-semi??????????? 保留所有的分号。
?? --disable-optimizations??? 禁止优化。