It's impossible to reliably set up Closure compiler if you are outside of Google's infrastructure and/or outside of Google's Closure Library.
End of comparison.
It's impossible to reliably set up Closure compiler if you are outside of Google's infrastructure and/or outside of Google's Closure Library.
End of comparison.
Just pipe your JavaScript into Closure and it will minify it as easily as Uglify. We're migrating to Webpack, but we've been using this for about 4 years:
node_modules/.bin/browserify index.js | closure-compiler \
--warning_level quiet \
--third_party \
--jscomp_off es3 \
--compilation_level SIMPLE_OPTIMIZATIONS \
--language_in ECMASCRIPT5 \
--create_source_map "index.min.js.map" \
--output_wrapper "%output%//# sourceMappingURL=/index.min.js.map" \
> index.min.js
This generates a minified file plus a source map.Part of the magic happens in Browserify [1], which generates a single file from all your inputs, taking care to follow the import chains in the correct order. If you have ES6 code, you'll just install Babel and add "-r babel-register" to the Browserify command line.
I read the rant in your other comment, and I don't understand what it was that you struggled with. You certainly don't need to follow Google's Closure conventions in order for it to optimize and minify your code effectively. We don't; we use React and Babel with all the ES6 bells and whistles, but none of the Google conventions.
So maybe concatenating everything works with Closure Compiler. I don't know. We couldn't make it work with their advertised support for node_modules.
In my personal experience I couldn't get the compiler (none of the versions) work with a simple-enough project and node_modules in all the correct places.
UglifyJS just works.
- The official docs are basically non-existent.
- If you're lucky enough to realize that GitHub wiki has better docs, good luck figuring them out.
- Even though the support for node_modules is kinda finally there, it's still impossible to figure out how to reliably set the compiler in a way that recognizes them.
My old-ish rant about this: https://gist.github.com/dmitriid/7bd6f2c10d263bae40e0addc7ed...