Skip to content

Commit a7d74da

Browse files
committed
build(app): wire vendor manualChunks into vite
1 parent 99fab22 commit a7d74da

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎app/vite.config.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig } from "vite";
22
import react from "@vitejs/plugin-react";
3+
import { manualChunks } from "./src/build/manualChunks";
34

45
// @ts-expect-error process is a nodejs global
56
const host = process.env.TAURI_DEV_HOST;
@@ -8,6 +9,21 @@ const host = process.env.TAURI_DEV_HOST;
89
export default defineConfig(async () => ({
910
plugins: [react()],
1011

12+
// 批 2 包体治理:vendor 分组。
13+
// Why 放在这里而不是对象形式 `{ "vendor-react": ["react", …] }`:
14+
// ① 对象形式在包未安装时**直接让构建失败**(rollup 解析不到入口),
15+
// 而本批必须为批 6 的 GSAP 预留一个「现在惰性、将来自动生效」的槽;
16+
// ② 函数形式可以按**解析出的包名**精确匹配,避开 `node_modules/react`
17+
// 同时是 react-dom / react-markdown / @xyflow/react 子串的碰撞陷阱。
18+
// 规则与单测见 src/build/manualChunks.ts(纯函数,tsc 与 vitest 都覆盖得到)。
19+
build: {
20+
rollupOptions: {
21+
output: {
22+
manualChunks: (id: string) => manualChunks(id),
23+
},
24+
},
25+
},
26+
1127
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
1228
//
1329
// 1. prevent Vite from obscuring rust errors

0 commit comments

Comments
 (0)