5 ms·
Those features are supported in Webpack and other bundlers. Code splitting: https://webpack.js.org/guides/code-splitting/ https://webpack.js.org/guides/code-sp
by kolme 9y ago
Those features are supported in Webpack and other bundlers.
Code splitting:
https://webpack.js.org/guides/code-splitting/ https://webpack.js.org/guides/code-splitting/
Tree shaking:
https://webpack.js.org/guides/tree-shaking/ https://webpack.js.org/guides/tree-shaking/
- cromwellian 9y agoIt's not quite the same. It has some aspects of Google's module system in terms of de-duping (our internal version automatically splits up all code referenced in more than one place into a tree of synthetic modules) But Closure's optimizations go far beyond the "tree shaking" described here, which is really about pruning unused module dependencies. Closure does pruning of methods, properties, etc at a fine grained level, moves code at a per-method level between modules, it computes whether functions have side effects and elides unused side-effect-free code, it does type-based optimizations (https://github.com/google/closure-compiler/wiki/Type-Based-Property-Renaming https://github.com/google/closure-compiler/wiki/Type-Based-P...), the list goes on and on. It's really like having GCC or LLVM for Javascript code. That's one reason why it's slow, because it does far more than the transpilers and minimizers out there. (As many in another, GWT does many of the same things, being a fully optimizing true compiler)
- lennelpennel 9y agoI want to add that you can easily write your own compile pass for the closure compiler as well. All the optimisations described above are just compile passes.
- coldtea 9y agoOnly in a very primitive way.
- pas 9y agohttps://github.com/webpack/webpack/issues/2867 https://github.com/webpack/webpack/issues/2867 - "Tree shaking completely broken?" It turns out that it basically supported "skip loading of unnecessary ES6 modules", so kind of like a "warn: unused import", but turned into a silence and no-op. Now with Uglify getting the "pure" annotation, and libraries sprinkling that onto their code, it'll help a bit.
- fnordsensei 9y agoReact moved some parts from Uglify to Closure recently. They're only compiling using "simple" ("none" and "advanced" are the other options), but they're still seeing benefits: https://github.com/facebook/react/pull/10236 https://github.com/facebook/react/pull/10236