(no title)
throwAGIway | 1 year ago
This is tree shaking though, dead code elimination means it will find code that isn't used at all and remove it - for example you might have if (DEV) {...}, and DEV is static false at build time, the whole if is removed.
So first it performs dead code elimination, then it removes unused imports, and then it calculates what is actually needed for your imports and removes everything else.
benrutter|1 year ago
Makes me wonder why some js bundles are still so big, am I over hyping what dead code elimination and tree shaking might achieve? Do some teams just not use it?
Either way, I've come away from my question with a pretty big reading list. This is exactly what I love about HN.
tubthumper8|1 year ago
Some bundles may still be big if teams don't use it, and some libraries are not structured in a way that facilitates dead code elimination.
Consider libraries that use `class`, such as moment.js, all functionality is made available as methods on the Moment class. If you only use 1 method, you still have to bring in the whole class. Whereas if a library is structured as free functions and you only use one, then only that gets included and the rest is eliminated.