Webpack 打包速度太慢怎么优化?

设计师彦杰 阅读 32

我项目里用了 Webpack 5,现在每次开发时热更新都要等十几秒,改一行代码就得卡半天。试过加 cache: { type: 'filesystem' },也用了 thread-loader,但效果不明显。

我的配置里 babel-loader 和 ts-loader 都有,是不是哪里没配对?有没有更有效的提速方法?下面是部分配置:

module.exports = {
  module: {
    rules: [
      {
        test: /.tsx?$/,
        use: ['thread-loader', 'ts-loader'],
        exclude: /node_modules/,
      },
      {
        test: /.js$/,
        use: ['thread-loader', 'babel-loader'],
        exclude: /node_modules/,
      }
    ]
  },
  cache: {
    type: 'filesystem'
  }
};
我来解答 赞 3 收藏
二维码
手机扫码查看
1 条解答
FSD-志诚
增加 exclude 范围,比如忽略 node_modules 之外的某些文件夹;尝试用 swc-loader 替换 babel-loader 和 ts-loader,速度快很多;搞定。
点赞
2026-03-24 10:41