Google Closure Complier使用心得與文檔

來源:互聯網
上載者:User

嘗試了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了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.