Webpack打包优化(2)

将第三库分割成多个文件

  • 利用浏览器缓存
  • HTTP2 并发数量没有限制

使用SplitChunksPlugin进行手工分割

splitChunks=[
 maxInitialRequest:Infinity,
 maxSize:0,
 chunks:'all',
 cacheGroups:{
  antVendor:{
    name :'ant-design',
    test:/[\\/]node_modules[\\/](ant-design-vue)[\\/]/,
  },
  vendor:{
  name :'vendor',
  test:/[\\/]node_modules[\\/](!ant-design-vue)[\\/]/,
  }
 }
]

根据文件大小自动分割

splitChunks=[
 maxInitialRequest:Infinity,
 maxSize:300*1024,
 chunks:'all',
 cacheGroups:{
  antVendor:{
  test:/[\\/]node_modules[\\/]/,
name(module):{
const packageName=module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
return `npm.{packageName.replace('@','')`
}

  }
 }
]
posted @   mengxiangzhi  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示