瘦身 P1-3: 后管入口 chunk 拆出 vue 运行库(只拆 vue,不拆 element-plus)

实测三组数(npm run build 后 dist/assets/*.js 字节和):
  改动前  total 1072.4 KB / 入口 index 751.1 KB(占 70.0%)
  只拆 vue  total 1048.1 KB / 入口 622.2 KB(占 59.4%)+ vue 独立 111.2 KB
  再拆 EP   total 1431.5 KB —— 反涨 384 KB,因为 manualChunks 点名 'element-plus'
            会把整包拖进一个 chunk,打穿 plugins/element.ts 那 30 个组件的 tree-shaking,
            首屏反而多载 893.9 KB。这一档已撤回。

所以这条的真实收益是缓存性(改页面代码不再作废 111 KB 的 vue 运行库),
不是字节数:首屏总量基本不变。指南阈值表里"入口占比 70%"看着像该拆,实测只对一半。

验证:npm test ⇒ 1819 tests / 1819 pass / 0 fail;npm run test:mount ⇒ 21 passed (4 files);
      tests/admin-scaffold.test.ts 钉的 base 与 outDir 两条断言仍绿。
This commit is contained in:
2026-10-15 13:40:29 +08:00
parent 8396a32475
commit abfacb1081
+7
View File
@@ -33,5 +33,12 @@ export default defineConfig({
outDir: 'dist',
emptyOutDir: true,
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vue: ['vue', 'vue-router', 'pinia'],
},
},
},
},
})