@echo off
if not exist "%JAVA_HOME%" set JAVA_HOME=D:\Java\jdk1.5.0_15
echo **************************************************
echo 调用方法:buildJS.bat JS版本号
echo 如:buildJS.bat
echo **************************************************
set CURDIR=%cd%
set ver=%1
set ver1=%1
:writeVersion
if "%ver%"=="" (
echo "请输入版本信息:"
@set /p ver=:
goto writeVersion
)else(
echo "是否确认版本信息:y/n"
@set /p ver1=:
if "%ver1%"=="y"||"%ver1%"=="Y"()
else(
goto writeVersion
)
)
if exist %CURDIR%\target rd /s /q %CURDIR%\target
mkdir %CURDIR%\target
mkdir %CURDIR%\target\js22
echo 复制文件到target目录下
xcopy ..\js22 %CURDIR%\target\js22 /e /q
cd %CURDIR%\target\js22
for /r %%a in (*.js) do (
echo 压缩文件%%a
call java -jar %CURDIR%\lib\yuicompressor.jar --type js -o %%a %%a
)
echo 生成zip包
cd %CURDIR%
call ant\7z a -tzip %ver%.zip %CURDIR%\target\js22\*
jar 文档说明:
==============================================================================
YUI Compressor
==============================================================================
NAME
YUI Compressor - The Yahoo! JavaScript and CSS Compressor
SYNOPSIS
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 number
-v, --verbose Display informational messages and warnings
-o <file> Place the output into <file>. Defaults to stdout.
JavaScript Options
--nomunge Minify only, do not obfuscate
--preserve-semi Preserve all semicolons
--disable-optimizations Disable all micro optimizations
DESCRIPTION
The YUI Compressor is a JavaScript compressor which, in addition to removing
comments and white-spaces, obfuscates local variables using the smallest
possible variable name. This obfuscation is safe, even when using constructs
such as 'eval' or 'with' (although the compression is not optimal is those
cases) Compared to jsmin, the average savings is around 20%.
The YUI Compressor is also able to safely compress CSS files. The decision
on which compressor is being used is made on the file extension (js or css)
GLOBAL OPTIONS
-h, --help
Prints help on how to use the YUI Compressor
--line-break
Some source control tools don't like files containing lines longer than,
say 8000 characters. The linebreak option is used in that case to split
long lines after a specific column. It can also be used to make the code
more readable, easier to debug (especially with the MS Script Debugger)
Specify 0 to get a line break after each semi-colon in JavaScript, and
after each rule in CSS.
--type js|css
The type of compressor (JavaScript or CSS) is chosen based on the
extension of the input file name (.js or .css) This option is required
if no input file has been specified. Otherwise, this option is only
required if the input file extension is neither 'js' nor 'css'.
--charset character-set
If a supported character set is specified, the YUI Compressor will use it
to read the input file. Otherwise, it will assume that the platform's
default character set is being used. The output file is encoded using
the same character set.
-o outfile
Place output in file outfile. If not specified, the YUI Compressor will
default to the standard output, which you can redirect to a file.
-v, --verbose
Display informational messages and warnings.
JAVASCRIPT ONLY OPTIONS
--nomunge
Minify only. Do not obfuscate local symbols.
--preserve-semi
Preserve unnecessary semicolons (such as right before a '}') This option
is useful when compressed code has to be run through JSLint (which is the
case of YUI for example)
--disable-optimizations
Disable all the built-in micro optimizations.
NOTES
+ If no input file is specified, it defaults to stdin.
+ The YUI Compressor requires Java version >= 1.4.
+ It is possible to prevent a local variable, nested function or function
argument from being obfuscated by using "hints". A hint is a string that
is located at the very beginning of a function body like so:
function fn (arg1, arg2, arg3) {
"arg2:nomunge, localVar:nomunge, nestedFn:nomunge";
...
var localVar;
...
function nestedFn () {
....
}
...
}
The hint itself disappears from the compressed file.
+ C-style comments starting with /*! are preserved. This is useful with
comments containing copyright/license information. For example:
/*!
* TERMS OF USE - EASING EQUATIONS
* Open source under the BSD License.
* Copyright 2001 Robert Penner All rights reserved.
*/
becomes:
/*
* TERMS OF USE - EASING EQUATIONS
* Open source under the BSD License.
* Copyright 2001 Robert Penner All rights reserved.
*/
AUTHOR
The YUI Compressor was written and is maintained by:
Julien Lecomte <jlecomte@yahoo-inc.com>
The CSS portion is a port of Isaac Schlueter's cssmin utility.
COPYRIGHT
Copyright (c) 2007-2009, Yahoo! Inc. All rights reserved.
LICENSE
All code specific to YUI Compressor is issued under a BSD license.
YUI Compressor extends and implements code from Mozilla's Rhino project.
Rhino is issued under the Mozilla Public License (MPL), and MPL applies
to the Rhino source and binaries that are distributed with YUI Compressor.
分享到:
相关推荐
这个jar包包含了yuicompressor的核心功能,只需简单的命令行操作或者集成到构建流程中,就能实现对JavaScript代码的压缩,减少冗余的空格、注释以及进行变量名混淆,达到减小文件体积的目的。 使用yuicompressor-...
1. **去除空白与注释**:YUI Compressor会删除代码中的多余空格、换行和注释,这是最基本的压缩方式,能有效减少文件大小而不影响代码执行。 2. **变量与函数混淆**:为了进一步压缩,YUI Compressor会对变量和函数...
\n\n总的来说,通过ANT结合YUI Compressor进行JS压缩,不仅可以有效地减小文件大小,加快页面加载,还能通过去除空格和注释提高执行效率。然而,这可能会影响代码的可读性和调试性,因此通常在生产环境使用压缩版,...
为了减少网络传输的数据量,开发者通常会使用专门的工具对JavaScript代码进行压缩,去除不必要的空格、注释以及进行变量混淆等操作。"JSA脚本压缩工具"就是这样一款实用的软件,它能够帮助我们高效地完成JavaScript...
在Java开发中,压缩JavaScript(js)和CSS(样式表)文件是一项常见的优化技术,用于减少网页加载时间和提高用户体验。这种技术通常被称为“文件合并与压缩”,它将多个js和css文件合并为一个文件,并去除其中不必要...
)开发的一款开源JavaScript和CSS压缩工具,其主要功能是去除代码中的空格、换行和注释,同时还能进行变量名混淆,进一步减小文件大小。YUI Compressor的版本号为2.4.8,这表明它已经经过了多次迭代和优化,能够稳定...
java -jar yuicompressor-x.x.x.jar input.js -o output.js --type js java -jar yuicompressor-x.x.x.jar input.css -o output.css --type css ``` 其中,`x.x.x`是版本号,`input.js`和`input.css`分别为输入...
CSS压缩同样涉及到去除空格、注释和换行,但与JS不同,CSS还有一种特殊的优化方式——CSS预处理器(如Sass、Less),它们允许编写更结构化的CSS代码,然后在编译时自动压缩。此外,CSS Sprites技术可以将多个小图...
开发的开源工具,它能压缩JavaScript和CSS,去除注释、空格并进行变量名混淆,以达到最小化文件的效果。 - **jspacker.jar**:另一款JavaScript压缩工具,它除了基本的压缩功能外,还提供了变量加密,增加代码的...
例如,`java -jar yuicompressor.jar input.css -o output.css --type css` 可以压缩CSS文件,`java -jar yuicompressor.jar input.js -o output.js --type js` 则用于压缩JavaScript文件。 3. **批量处理**:如果...
在命令行中,你可以输入类似`java -jar yuicompressor.jar input.js -o output.js`的命令,将`input.js`进行压缩并保存为`output.js`。 需要注意的是,虽然混淆和压缩可以增强代码安全性,但它们并不能提供绝对的...
其中,`yuicompressor-2.4.7.jar`是一个著名的CSS和JS压缩工具——YUI Compressor的Java版本。它由雅虎开发,能有效地压缩JavaScript和CSS,通过消除冗余代码和压缩语法,显著减小文件体积。 压缩JS文件的原理类似...
- **yuicompressor-2.4.6.jar**: 这是YUI Compressor的Java可执行文件,是用于压缩JS和CSS的核心组件,支持去除代码中的空格、换行和注释,从而减小文件大小。 - **使用说明.txt**: 提供了详细的工具使用指南,帮助...
1. **代码压缩**:去除空格、换行符和注释,将多个小字符串合并为一个,减少HTTP请求。 2. **变量混淆**:将变量名替换为更短的形式,降低代码可读性但不影响执行。 3. **死代码消除**:识别并移除未使用的变量、...
YUI Compressor的主要功能是将JavaScript和CSS代码进行压缩,通过删除不必要的空格、换行符以及简化注释,来减小文件大小,从而加快页面加载速度。此外,它还支持CSS的合并,可以将多个CSS文件整合为一个,进一步...
JavaScript压缩主要目标是去除代码中的空白、注释和不必要的字符,以达到最小化的目的。`yuicompressor-2.4.2` 是一个经典的JS压缩工具,由Yahoo!开发。它不仅能够压缩JS代码,还支持CSS压缩。YUI Compressor通过JAR...
HTML、CSS和JavaScript是网页开发中的三大核心技术,它们在构建交互式、动态和美观的网页时起着至关重要的作用。然而,未经优化的代码会增加页面加载时间,影响用户体验。因此,HTML、CSS和JS的压缩工具就显得尤为...