Previously, I have been using the following build script in order to compile a Closure project:
# BUILD SCRIPT 1:
closure-library/closure/bin/build/closurebuilder.py \
--root=closure-library/ \
--root=src/ \
--namespace="entrypoint" \
--output_mode=compiled \
--compiler_jar=compiler.jar \
--compiler_flags="--js=closure-library/closure/goog/deps.js" \
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" \
> ../public_html/scripts/compiled.js
This works correctly, but yields the following output:
closure-library/closure/bin/build/closurebuilder.py: Closure Compiler
now natively understands and orders Closure dependencies and
is prefererred over using this script for performing JavaScript
compilation.
Please migrate your codebase.
See:
https://github.com/google/closure-compiler/wiki/Managing-Dependencies
After much experimentation, I finally got the compiler working correctly (including the necessary goog.
libs):
# BUILD SCRIPT 2:
java -jar compiler.jar \
--js "src/**.js" \
--js "closure-library/closure/goog/**.js" \
--js "!closure-library/closure/goog/**_test.js" \
--dependency_mode=STRICT \
--entry_point=entrypoint \
--compilation_level=ADVANCED_OPTIMIZATIONS \
--js_output_file=../public_html/scripts/compiled.js
This yields similar compiled code (some parts are re-ordered, some variable names are changed, but no important differences). However, build script 2 takes about 50% longer to run (45 seconds as compared to 30 seconds).
Is my build script 2 somehow incorrect / less efficient than it should be? If not, why is the significantly slower compilation method "preferred"?
All the code actually gets parsed by closure-compiler, whereas closure-builder uses regex matching (I believe).
Closure-builder doesn't cover many modern dependencies such as CommonJS or ES6 modules - thus the migration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With