Closure Compilerを使う!
Closure Compiler Application:コマンドラインオプション
最終更新:
aias-closurecompiler
トップページ > Closure Compiler Application >
Closure Compiler Application:コマンドラインオプション
このページでは、Closure Comiler Applicationのコマンドラインオプションについて詳細に説明します。Closure Comiler Applicationの使用方法についてはこちらを参照してください。
- このページは--helpオプションで出力されるヘルプの情報を元に作成しました。尚、管理人が使い方を理解できなかったオプションについてはヘルプの原文(英語)をそのまま記載しています。
目次:
- 主なオプション
-
その他のオプション
- --compute_phase_ordering
- --create_name_map_files
- --create_source_map
- --debug
- --define (--D, -D)
- --jscomp_dev_mode (--dev_mode)
- --jscomp_error
- --jscomp_off
- --jscomp_warning
- --logging_level
- --module
- --module_output_path_prefix
- --module_wrapper
- --output_manifest
- --output_wrapper
- --output_wrapper_marker
- --print_ast
- --print_pass_graph
- --print_tree
- --process_closure_primitives
- --property_map_input_file
- --property_map_output_file
- --summary_detail_level
- --third_party
- --variable_map_input_file
- --variable_map_output_file
主なオプション
--charset
--charset VAL
全ての入力ファイルの文字エンコーディングを指定します。(入力ファイルは全て同じ文字エンコーディングを使用していなくてはなりません。)省略した場合、ファイルの文字エンコーディングは UTF-8 であると解釈されます。
--compilation_level
--compilation_level [WHITESPACE_ONLY|SIMPLE_OPTIMIZATIONS|ADVANCED_OPTIMIZATIONS]
JavaScriptに適用する圧縮と最適化の度合い(コンパイルレベル)を指定します。以下の3つのレベルがあります:
-
WHITESPACE_ONLY
JavaScriptから空白・改行とコメントだけを削除します。
-
SIMPLE_OPTIMIZATIONS
WHITESPACE_ONLY での処理に加えてローカル変数のリネームを行い、コードの圧縮と最適化を行います。このレベルではコンパイルされたコードとそれ以外のコードとの連携が妨げられることはありません。
-
ADVANCED_OPTIMIZATIONS
SIMPLE_OPTIMIZATIONS での処理に加えてグローバル領域を含むシンボルのリネームを行い、最高レベルの圧縮度を実現します。 ADVANCED_OPTIMIZATIONS を使用する場合、外部のシンボルとの参照関係を維持するために追加の手順を実行する必要があります。 ADVANCED_OPTIMIZATIONS レベルのコンパイル処理が求める様々な制約については、こちらを参照してください。
オプション指定を省略した場合は SIMPLE_OPTIMIZATIONS が適用されます。
--externs
--externs VAL
コンパイル対象となっていないコード上で定義されたシンボル名がリネームされるのを防ぐためのexternファイルを指定します。このオプションが効果をもつのはcompilation_levelオプションの値が ADVANCED_OPTIMIZATIONS の場合のみです。externに関して詳しくはこちらを参照してください。
複数のexternファイルがある場合はこのオプションを複数指定してください。
--formatting
--formatting [pretty_print|print_input_delimiter]
出力されるコンパイル済みJavaScriptコードの整形方式を指定します。このオプションは pretty_print または print_input_delimiter のどちらかの値をとりますが、2つの formatting オプションによってこれらを同時に指定することが可能です。 pretty_print と print_input_delimiter は整形方法のそれぞれ異なる側面についての指示であるため、重複しても互いに影響しあうことがありません。
-
pretty_print
人間が読み易くなるよう出力コードに改行とインデントを付加します。以下にその例を示します:
function hello(a) {
alert("Hello, " + a)
}
hello("New user");pretty_print がない場合は次のようになります。
function hello(a){alert("Hello, "+a)}hello("New user");
-
print_input_delimiter
各入力ファイルの範囲を示す文字列を出力コード内に付加します。例えば2つのファイルを一緒にコンパイルした場合、出力は次のようになります:
// Input 0
alert("hi");
// Input 1
alert("bye");ファイル間の境界を表す区切り文字としてClosure Compilerは「 // Input X 」を挿入します。これらの区切り文字はコメントであり、JavaScriptの動作を妨げない点に注意してください。入力ファイルの区切りには、例えば各ファイルのサイズ圧縮度の把握を助けるというような用途が考えられます。
--help
--help
コンソールにオプションのリストを表示し、処理を終了します。
--js
--js VAL
入力JavaScriptファイル名を指定します。複数の入力ファイルがある場合はオプションを複数指定してください。このオプションが未指定の場合、出力結果は空文字列となります。
--js_output_file
--js_output_file VAL
出力ファイル名を指定します。省略した場合、処理結果は標準出力に出力されます。
--manage_closure_dependencies
--manage_closure_dependencies [true|false]
true を指定した場合、 goog.provide で定義されたシンボルは必ずそれを要求する goog.require より前に存在する、という関係に基づいて自動的にファイルのソートを実行します。もし定義されたシンボルが一度も要求されなかった場合、そのシンボルはコンパイル結果から除外されます。このオプションの詳細についてはこちらを参照してください。デフォルトは false です。
--use_only_custom_externs
--use_only_custom_externs [true|false]
Closure Compilerは document オブジェクトやそのメソッドのような標準的なシンボルを宣言したexternファイルを持っており、デフォルトではそれを使用してシンボル名の保護を行います。 --use_only_custom_externs オプションに true を指定するとこれらの標準的なexternを使用しなくなります。デフォルトのextern宣言に関する詳細はこちらを参照してください。デフォルトは false です。
--warning_level
--warning_level [QUIET|DEFAULT|VERBOSE]
コード内の問題になりそうな箇所に関する情報の量を指定します。警告レベルには以下の3種類があります:
-
QUIET
現在のコンパイルでのcompilation_levelに基づく最適化パスで生成された文法エラーと警告のみを出力します。
-
DEFAULT
最適化パスで生成された文法エラーと警告に加え、選択されたコードチェックパス上で生成された警告を出力します。 warning_level オプションのデフォルト値です。
-
VERBOSE
最適化パスで生成された文法エラーと警告に加え、実行された全てのコードチェックパス上で生成された警告を出力します。
エラーと警告は標準エラー出力に出力されます。
その他のオプション
--compute_phase_ordering
--compute_phase_ordering
Runs the compile job many times, then prints out the best phase ordering from this run.
--create_name_map_files
--create_name_map_files [true|false]
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
--create_source_map VAL
Closure Inspectorのソースマッピング機能で使用するソースマップファイルの出力ファイルパスを指定します。ソースマップファイルにはコンパイルされたコードとオリジナルのコードとの位置関係がマッピングされています。指定に %output% という文字列を含めると、それはコンパイル結果の出力ファイル名がその位置に展開されるプレースホルダとして機能します。
--debug
--debug [true|false]
true を指定するとデバッグ用の出力を行ないます。デフォルトは false です。
--define (--D, -D)
--define (--D, -D) VAL
@define タグが付けられた変数を指定の値で上書きします。このオプションの値の書式は <name>[=<val>] で、 <name> には @define タグが付与された変数の名前を、 <val> には置き換えたい値を指定します。 <val> の値にはブール値、数値、シングルクォートされた文字列(ただしシングルクォートを含まない)を使用できます。 <val> が省略された場合は true が適用されます。
このオプションについてはこちらも参照してください。
--jscomp_dev_mode (--dev_mode)
--jscomp_dev_mode (--dev_mode) [OFF|START|START_AND_END|EVERY_PASS]
Turns on extra sanity checks.
--jscomp_error
--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
--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
--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
--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.
--module
--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
--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
--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
--output_manifest VAL
値としてファイル名を指定し、コンパイルされた全てのファイルのリストをそこに出力します。--manage_closure_dependenciesオプションが有効な場合、使用されなかったためにコンパイル対象にならなかったファイルはリストから除外されます。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
--output_wrapper VAL
このオプションに指定された文字列にコンパイル結果を内包して出力させます。以下に例を示します:
--output_wrapper (function(){%output%})()
%output% がコンパイルされたコードのプレースホルダとなります。上のような形式で出力するとコンパイルされたコードのスコープは外側の関数内に限定されるため、リネームされたシンボルによるグローバル領域の汚染を防止することができます。デフォルトのプレースホルダ %output% は--output_wrapper_markerによって任意の文字列に変更できます。
--output_wrapper_marker
--output_wrapper_marker VAL
--output_wrapperオプションにおいてコンパイルされたコードのプレースホルダとして使用されるトークン文字列を指定します。
--print_ast
--print_ast
Prints a dot file describing the internal abstract syntax tree and exits.
--print_pass_graph
--print_pass_graph
Prints a dot file describing the passes that will get run and exits.
--print_tree
--print_tree
Prints out the parse tree and exits.
--process_closure_primitives
--process_closure_primitives [true|false]
goog.require() 、 goog.provide() 、 goog.exportSymbol() のようなClosure Libraryの関数をコンパイル時にコードに展開します。デフォルトは true です。
- ヘルプには上のように書かれていますが、管理人の試した限りでは展開されるのは goog.require() と goog.provide() だけのようでした。
--property_map_input_file
--property_map_input_file VAL
File containing the serialized version of the property renaming map produced by a previous compilation.
--property_map_output_file
--property_map_output_file VAL
File where the serialized version of the property renaming map produced should be saved.
--summary_detail_level
--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
--third_party
Check source validity but do not enforce Closure style rules and conventions.
--variable_map_input_file
--variable_map_input_file VAL
File containing the serialized version of the variable renaming map produced by a previous compilation.
--variable_map_output_file
--variable_map_output_file VAL
File where the serialized version of the variable renaming map produced should be saved.