Tree-shaking

Learn what the tree shaking is and where we can use it.

Tree shaking is a technique used by module bundlers to remove unused code from an application to reduce the final bundle size. This feature relies on the static structure of the ES2015 module syntax

This is a great way to optimize applications because less code means that browsers need to spend less time on parsing and processing the application.

Let’s look at three examples.

First example - lodash

If a library like lodash is included in our project, then here’s what should and shouldn’t be done. Also, remember that tree-shaking is syntax-sensitive. See examples below:

...