webpack rebuild 速度太慢

查看:271
本文介绍了webpack rebuild 速度太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

工程的开发环境使用express+webpack-dev-middleware+webpack-hot-middleware,热加载+网页的错误提示开发起来很爽。

之前webpack每次启动的build速度都比较慢,后来参照这篇文章做了优化:
开发工具心得:如何 10 倍提高你的 Webpack 构建效率
加上dll plugin和happypack等之后,构建速度一下子由120s缩短到30s以内,随着工程越来越大(12万业务代码),rebuild速度越来越慢,现在一次rebuild速度大概得12s左右,实在是不能忍受。

哪位有这方面优化经验的,还请不吝赐教。

解决方案

There are quite a few conditions that can contribute to slowness. From personal experience, I have found that the best way about trying to solve it, is to Measure, Profile, and Diagnose the issue first.

When you run webpack, instead run it with node and the following flags:

node --inspect --debug-brk ./node_modules/webpack/bin/webpack.js

Then open up Chrome Browser and goto chrome://inspect and click 'Open Dedicated Node Debugger'.

This will give you debug, breakpoint, and profiling features that you can use to measure and analyze what functions and areas of webpack are taking the longest. Once you have found that out, you can start to determine exactly what is causing the issue. Here is a great post (although a little outdated for the instructions), that shows how these steps might look like

If this doesn't help, then you can try other webpack build features like DllPlugin, using devtool: 'eval-source-map', look for specific loaders that have caching features, as well as our new cache-loader.

这篇关于webpack rebuild 速度太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆