JavaScript tree shaking, like a pro

This file exports two utility functions…
…but since only initializeName is actually used, formatName can be dropped entirely
All of the above are possible with commonjs
ES6 imports and exports have far simpler semantics, and restricted usage.
Here, both functions will be bundled, even if only one is ever used
And here, the entire class will be bundled any time it’s used
Now, if only one of these functions is ever used, only one will be bundled
Webpack has no idea what window.memoize will do here, so it can’t tree-shake the add function
Give Webpack as much information as you can, and you’ll get a better bundle

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store