How to improve webpack performance?

旧城冷巷雨未停 提交于 2019-12-02 20:25:40
Juho Vepsäläinen

You should set include paths for your loaders. Example:

{ test: /\.js$/, loader: 'jsx-loader', include: jsSrcPath }

Consider doing the same for that css case.

In my experience this can give massive gains as it doesn't have to traverse through node_modules anymore. Alternatively you could exclude node_modules but I find it neater just to set up that include. It gets more complicated if you are requiring content out of the include path, though.

Docs for include/exclude

Jeff Ling

You can use the noParse option for big files, like jquery and angular.

Examples here: https://github.com/jeffling/angular-webpack-example/blob/b2b59dff60c35ee6d70170948ab15bba8af5e613/template/webpack.config.coffee#L60

Also, if you set cache to true, when watching it rebuilds a lot faster.

Another technique to increasing speed is to put big dependencies that you aren't going to edit into a separate bundle.

Recently a new module loader, HappyPack (not written by me), makes heavy use of parallelization and disk caching to improve build times on large code bases pretty significantly. Compile times on my code base went from 40 seconds to 10. It's still a pretty new library though, so it's not extremely well documented or user friendly. Worth taking a look at though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!