Closed qnp closed 4 years ago
Use tree-shaking.
Example in a project depending on 'swing', using webpack as a build system and webpack-bundle-analyser plugin:
Tree shaking was not possible due to current import syntax.
c.f. https://www.azavea.com/blog/2019/03/07/lessons-on-tree-shaking-lodash/
Tree-shaking is syntax-sensitive. To enable tree-shaking in lodash, you have to import functions using syntax like
import foo from 'lodash/foo'
.import { foo } from 'lodash'
will not tree-shake, nor will, obviously,import _ from 'lodash'
. Support for this syntax was implemented in Lodash v4.
A better solution would be https://github.com/lodash/babel-plugin-lodash.
PRs like this require that everyone is magically aware of this requirement.
This allows to reduce final bundle size