3 ms·
Luckily, that's not correct. 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
by lobster_johnson 10y ago
Luckily, that's not correct.
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.
[1] http://browserify.org http://browserify.org
- dmitriid 10y agoWe moved away from browserify and the need to concatenate everything about two years ago, and we're definitely never going back :) 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.
- lobster_johnson 10y agoWhy do you need to minify if you're not bundling?
- dmitriid 10y agoWe are bundling. That's the last step after all the code has bin babelified etc. So Closure compiler will do nothing, really. And it fails spectacularly on webpack's helper functions that are bundled in (especially if the functions are exctracted to the HTML file)