K
K
keeiyo2016-06-24 12:47:37
webpack
keeiyo, 2016-06-24 12:47:37

How to remove unused modules in webpack?

The essence of the problem is that the compiled file grows very large. Maybe someone knows if webpack has the ability to remove unused modules from the final file?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2016-06-24
@maxfarseer

Webpack collects what you include. There are a couple of tips:
1. Connect carefully (for example, import _ from lodashuse instead of import func_name from lodash/func_name)
Developers try to optimize imports, so look for similar features in other libraries ( for example , ).
2. As you wrote in the question - remove unused code from the bundle (final script file). For example, uglifyJS can help with this. It should cut out everything unused. I won't give exact settings ( list ), but you can take a look at this question
3. Use a linter, for example eslint.org/. Run lint on the codebase and remove all unused (but included) modules.
ps While writing the answer to your question, I also came across webpack-bundle-size-analyzer . Haven't used it myself, but it might help.

A
Artem Kayun, 2016-06-24
@Kayun

Watch this video https://youtu.be/XY2NLKCrjJ4 , everything is explained in detail.
You can watch the entire screencast.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question