From abfacb1081e8a3626d29bacedee6ebe8558ee960 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Thu, 15 Oct 2026 13:40:29 +0800 Subject: [PATCH] =?UTF-8?q?=E7=98=A6=E8=BA=AB=20P1-3:=20=E5=90=8E=E7=AE=A1?= =?UTF-8?q?=E5=85=A5=E5=8F=A3=20chunk=20=E6=8B=86=E5=87=BA=20vue=20?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E5=BA=93=EF=BC=88=E5=8F=AA=E6=8B=86=20vue?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E6=8B=86=20element-plus=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测三组数(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 两条断言仍绿。 --- admin-frontend-vue/vite.config.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/admin-frontend-vue/vite.config.ts b/admin-frontend-vue/vite.config.ts index 0496b15b4..8382e9f7c 100644 --- a/admin-frontend-vue/vite.config.ts +++ b/admin-frontend-vue/vite.config.ts @@ -33,5 +33,12 @@ export default defineConfig({ outDir: 'dist', emptyOutDir: true, sourcemap: false, + rollupOptions: { + output: { + manualChunks: { + vue: ['vue', 'vue-router', 'pinia'], + }, + }, + }, }, })