Google Closure Complier使用心得与文档

尝试了N多次之后俺终于放弃使用Google Closure Compiler 来编译Mootools 了,原因很简单,Google Closure 不能混合使用[""] 与 . 的属性访问方式,导致部分代码在混淆之后不可使用。

 

Standard flags:
   --help describes all flags
   --helpshort describes the main class' flags
   --helpxml emits XML description of all flags

  Flags for com.google.javascript.jscomp.AbstractCompilerRunner:
   --charset Input charset for all files.; default:
   --create_source_map If specified, a source map file mapping the
      generated source files back to the original source file will be
      output to the specified path. If %module% is added, a source map
      will be generated for each module, with the  module's name
      placed into the path at that spot.; default:
   --D 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.; default:
   --externs 保留符号文件列表,比如: function ABC(){};  则所有的ABC不会被混淆,有别于Export,Export只保留一个原名称的别名,其它的均被混淆,如果只是单纯向外部提供接口推荐使用Export方式
   --js The javascript filename. You may specify multiple; default:
   --js_output_file Primary output filename. If not specified, output
      is written to stdout.; default:
   --jscomp_error Make the named class of warnings an error.; default:

   --jscomp_off Turn off the named class of warnings.; default:
   --jscomp_warning Make the named class of warnings a normal
      warning.; default:
   --module 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.;
      default:
   --module_output_path_prefix 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.;
      default: ./
   --module_wrapper 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.; default:
   --output_wrapper Interpolate output into this string at the place
      denoted by the marker token %output%. See
      --output_wrapper_marker; default:
   --output_wrapper_marker Use this token as output marker in the
      value of --output_wrapper; default: %output%
   --property_map_output_file File where the serialized version of the
      property renaming map produced should be saved.; default:
   --summary_detail_level 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.; default: 1
   --third_party Check source validity but do not enforce Google style
      rules and conventions, such as capitalized constant names or
      opt_parameter.; default: false
   --variable_map_input_file File containing the serialized version of
      the variable renaming map produced by a previous compilation.;
      default:

  Flags for com.google.javascript.jscomp.CompilerRunner:
   --compilation_level Specifies the compilation level to use.
      Options: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS,
      ADVANCED_OPTIMIZATIONS; default: SIMPLE_OPTIMIZATIONS
   --debug Enable debugging opitons.; default: false
   --formatting :格式化方式 : 默论不格式化,或者 PRETTY_PRINT
   --process_closure_primitives Processes built-ins from the Closure
      library, such as goog.require(), goog.provide(), and
      goog.exportSymbol().; default: true
   --use_only_custom_externs Specifies whether the default externs
      should be excluded.; default: false
   --warning_level Specifies the warning level to use. Options: QUIET,
      DEFAULT, VERBOSE; default: DEFAULT

 

使用模块化编译的例子,使用高级压缩功能: java -jar compiler.jar --module m1:1 --js m1_1.js --module m2:1:m1 --js m2_1.js --compilation_level ADVANCED_OPTIMIZATIONS

 

说明:

将代码分别编译为m1 和m2两个模块, m1, m2 包含1个js文件( "m1:1", "m2:1" ),这里包含文件数量必须与紧跟后面的 --js传入的文件数目一致,如果有多个文件应该使用多个 --js 参数指定。

 

m2:1:m1 的意思是 m2 这个模块里面包含有一个文件,并依赖于m1模块。

 

依赖顺序不能搞乱。 如果是使用 Google自己的库可以使用库里面自带那个python脚本计算依赖关系。

 

想偷懒的童鞋可以了解一下这个 Closure Lite  ,  这是将Google Closure 核心部分预编译好的版本,只有33Kb大小,非常适合做工具类使用完成一些轻量级的开发工作,有了这个可以不用jQuery了 ;)

posted on 2009-12-22 17:08  沙加  阅读(3596)  评论(0编辑  收藏  举报

导航