简体   繁体   中英

How to use closurebuilder.py to compile my library with Google Closure Compiler

Can't seem to find current information or a working solution to my problem. I'm trying to compile all the scripts in my /src directory as a standalone JavaScript library (as opposed to a Closure application). Although I am setting the flag --output_mode=compiled , the output of the compilation still has

var COMPILED=!0

Here's how I'm compiling:

1 - Concat all my .js files into a single file in ./tmp/concat.js 2 - Run concat.js through the compiler with the following command

./lib/closure/bin/build/closurebuilder.py \
     --root=/usr/local/google-closure/closure-library/ \
     --root=./tmp \
     --namespace=BB.go \
     --output_mode=compiled \
     --compiler_jar=/usr/local/google-closure/compiler.jar \
     --compiler_flags="--compilation_level=SIMPLE_OPTIMIZATIONS" \
     --compiler_flags="--create_source_map=bb.js.map" \
     --compiler_flags="--warning_level=VERBOSE" \
     --compiler_flags="--language_in=ECMASCRIPT5" \
 > bb.min.js

The output is bb.min.js which has the problem described above.

Quick note

If I compile it in ADVANCED_OPTIMIZATIONS mode, then I get the expected output (minus all the public interfaces being renamed, which I don't want, and I don't want to export all of them, either). What I want to do is compile in SIMPLE_OPTIMIZATIONS mode and white-space only (so I can offer the library as a un-minified/un-obfuscated as well).

I'm pretty sure --output_mode=compiled should be --output_mode="compiled"

Here's what mine looks like that works:

python Z:\scripts\closure\closure\bin\calcdeps.py^
 --path=Z:\scripts\closure\^
 --output_mode="compiled"^
 --compiler_jar=Z:\scripts\closure\other\compiler.jar^
 --compiler_flag=--compilation_level=ADVANCED_OPTIMIZATIONS^
 --compiler_flag=--use_types_for_optimization^
 --compiler_flag=--warning_level=VERBOSE^
 --input=Z:\scripts\closure\other\soyutils_usegoog.js^
 --input=Z:\scripts\closure\closure\goog\deps.js^
 --input=utils.js^
 --input=main.js^
 --input=templates.soy.js^
 --output_file=main.min.js

Note that you would need to modify this to match your paths/files and that mine is meant for a windows environment, so replace the ^ with \\ and the backslashes with forward slashes for paths.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM