Closure Compiler - JavaScript优化编译器

  Closure Compiler是一个开源的JS优化工具,它可以移除死代码,最小化代码,并检查JS代码中的问题。

  编译器是用Java做的,下载compiler.jar,然后通过命令行编译你的JS:
  java -jar compiler.jar --js demo.js --js_output_file demo_out.js

 

  这里http://closure-compiler.appspot.com/home在线优化;

 

  =======================

  选项:


注意:有些选项要跟boolean值,比如 --print_tree true

--charset VAL
Input and output charset for all files. By default, we accept UTF-8 as input and output US_ASCII
指定输入输出字符集.默认输入UTF-8,输出US_ASCII;

--compilation_level [WHITESPACE_ONLY|SIMPLE_OPTIMIZATIONS|ADVANCED_OPTIMIZATIONS]
Specifies the compilation level to use. Options: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZ ATIONS
指定优化级别: WHITESPACE_ONLY:优化掉注释,换行等; SIMPLE_OPTIMIZATIONS:还支持函数内部变量名优化; ADVANCED_OPTIMIZ:还支持内联等优化特性;

--compute_phase_ordering
Runs the compile job many times, then prints out the best phase ordering from this run

--create_name_map_files
If true, variable renaming and property renaming map files will be produced as {binary name}_vars_map.out and {binary name}_props_map.out. Note that this flag cannot be used in conjunction with either variable_map_output_file or property_map_output_file

--create_source_map VAL
If specified, a source map file mapping the generated source files back to the original source file will be output to the specified path. The %outname% placeholder will expand to the name of the output file that the source map corresponds to.

--debug
Enable debugging options

--define (--D, -D) VAL
Override the value of a variable annotated @define. The format is <name>[=<val>], where <name> is the name of a @define variable and <val> is a boolean, number, or a single-quoted string that contains no single quotes. If [=<val>] is omitted, the variable is marked true

--externs VAL
The file containing javascript externs. You may specify multiple

--formatting [PRETTY_PRINT | PRINT_INPUT_DELIMITER]
Specifies which formatting options,if any, should be applied to the output JS. Options: PRETTY_PRINT,PRINT_INPUT_DELIMITER

--help
Displays this message
输出帮助信息

--js VAL
The javascript filename. You may specify multiple
指定输入的待优化JS文件,可以指定多个

--js_output_file VAL
Primary output filename. If not specified, output is written to stdout
指定输出文件,如果不指定,直接输出到控制台

--jscomp_dev_mode (--dev_mode) [OFF | START | START_AND_END | EVERY_PASS]
Turns on extra sanity checks

--jscomp_error VAL
Make the named class of warnings an error. Options:accessControls,checkRegExp,checkTypes, checkVars,deprecated, fileoverviewTags,invalidCasts, missingProperties,nonStandardJsDocs, strictModuleDepCheck, undefinedVars, unknownDefines, visibility

--jscomp_off VAL
Turn off the named class of warnings.Options:accessControls, checkRegExp,checkTypes, checkVars, deprecated, fileoverviewTags, invalidCasts, missingProperties, nonStandardJsDocs, strictModuleDepCheck, undefinedVars, unknownDefines, visibility

--jscomp_warning VAL
Make the named class of warnings a normal warning. Options:accessControls, checkRegExp,checkTypes, checkVars,deprecated, fileoverviewTags,invalidCasts, missingProperties, nonStandardJsDocs, strictModuleDepCheck, undefinedVars, unknownDefines, visibility

--logging_level VAL
The logging level (standard java.util.logging.Level values) for Compiler progress. Does not control errors or warnings for the JavaScript code under compilation

--manage_closure_dependencies
Automatically sort dependencies so that a file that goog.provides symbol X will always come before a file that goog.requires symbol X. If an input provides symbols, and those symbols are never required, then that input will not be included in the compilation.

--module VAL
A javascript module specification.The format is <name>:<num-js-files>[:[<dep>,...][:]]]. Module names must be unique. Each dep is the name of a module that this module depends on.Modules must be listed in dependency order, and js source files must be listed in the corresponding order.Where --module flags occur in relation to --js flags is unimportant

--module_output_path_prefix VAL
Prefix for filenames of compiled js modules. <module-name>.js will be appended to this prefix. Directories will be created as needed. Use with --module

--module_wrapper VAL
An output wrapper for a javascript module (optional). The format is <name>:<wrapper>. The module name must correspond with a module specified using --module. The wrapper must contain %s as the code placeholder

--output_manifest VAL
Prints out a list of all the files in the compilation. If --manage_closure_dependencies is on, this will not include files that got dropped because they were not required. The %outname% placeholder expands to the js output file. If you're using modularization, using %outname% will create a manifest for each module.

--output_wrapper VAL
Interpolate output into this string at the place denoted by the marker token %output%. See --output_wrapper_marker

--output_wrapper_marker VAL
Use this token as output marker in the value of --output_wrapper

--print_ast
Prints a dot file describing the internal abstract syntax tree and exits

--print_pass_graph
Prints a dot file describing the passes that will get run and exits

--print_tree
Prints out the parse tree and exits
输出解析树,并退出

--process_closure_primitives
Processes built-ins from the Closure library, such as goog.require(), goog.provide(), and goog.exportSymbol( )

--property_map_input_file VAL
File containing the serialized version of the property renaming map produced by a previous compilation

--property_map_output_file VAL
File where the serialized version of the property renaming map produced should be saved

--summary_detail_level N
Controls how detailed the compilation summary is. Values: 0 (never print summary), 1 (print summary only if there are errors or warnings), 2 (print summary if type checking is on, see --check_types), 3 (always print summary). The default level is 1

--third_party
Check source validity but do not enforce Closure style rules and conventions

--use_only_custom_externs
Specifies whether the default externs should be excluded

--variable_map_input_file VAL
File containing the serialized version of the variable renaming map produced by a previous compilation

--variable_map_output_file VAL
File where the serialized version of the variable renaming map produced should be saved

--version
Prints the compiler version to stderr.
输出版本信息

--warning_level [QUIET | DEFAULT | VERBOSE]
Specifies the warning level to use. Options: QUIET, DEFAULT, VERBOSE

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值