优化

1.多线程构建

thread-loader、happypack

2.减小体积

js压缩 optimization:true
tree-shaking
loader的test/include/exclude配置,resolve.modules减少模块的搜索层级
压缩图片image-webpack-loader
gzip压缩
cdn引入公共包

3.减少请求

cdn缓存

打包后vender体积过大

vender中主要是公共包
第一种用externals来优化,
第二种用SplitChunks优化。

  1. splitChunks: {
  2. cacheGroups: {
  3. you-module-name: {
  4. name: you-module-name,
  5. test: 匹配规则,
  6. chunks:you-chunks,
  7. priority: 10, // 优先级
  8. enforce: true,
  9. },
  10. ...
  11. },
  12. },

参考:https://juejin.cn/post/6844904198023168013#heading-0

pollyfill

截屏2022-03-23 下午5.04.41.png
https://jkfhto.github.io/2019-10-17/webpack/%E4%BD%BF%E7%94%A8%E5%8A%A8%E6%80%81Polyfill%E6%9C%8D%E5%8A%A1/
Webapck5 核心打包原理全流程解析,看这一篇就够https://mp.weixin.qq.com/s/85S7i3z9pVJyMjVKqXHy6w