1
0

perf: 前端打包产物优化——路由级懒加载和 vendor 分包

- 使用 React.lazy() + Suspense 实现路由级代码分割
- 配置 manualChunks 将 react/tdesign/recharts 拆分为独立 vendor chunk
- 页面组件改为 export default 以支持动态导入
- 新增 bundle-optimization 规范,更新 frontend 导航规范
This commit is contained in:
2026-04-23 00:26:54 +08:00
parent 64dc66afa6
commit b3258e76df
8 changed files with 109 additions and 23 deletions

View File

@@ -2,6 +2,12 @@ import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'node:path'
const vendorChunks: Record<string, string[]> = {
'vendor-react': ['react', 'react-dom', 'react-router'],
'vendor-tdesign': ['tdesign-react', 'tdesign-icons-react'],
'vendor-recharts': ['recharts'],
}
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
@@ -18,4 +24,20 @@ export default defineConfig({
},
},
},
build: {
chunkSizeWarningLimit: 700,
rollupOptions: {
output: {
manualChunks(id) {
for (const [chunkName, modules] of Object.entries(vendorChunks)) {
for (const mod of modules) {
if (id.includes(`/node_modules/${mod}/`)) {
return chunkName
}
}
}
},
},
},
},
})