Webpack collects what you connect. There are a couple of tips:
1. To connect carefully (for example, instead of
import _ from lodash
import func_name from lodash/func_name
Developers try to optimize imports, so look for such opportunities from other libraries (for example
2. As you wrote in the question - remove from the bundle (final file script) unused code. This can help, for example, uglifyJS. He needs to cut out all the unused. The exact settings will not result (a list
), but I can look at this question
3. To use a Linter, e.g. eslint.org/.
To run lint
on a codebase and remove all the unused (but connected) modules.
p.s. while writing an answer to your question, I came across another webpack-bundle-size-analyzer
. He did not use, but might help.