File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,63 @@ export default defineConfig({
3737 // 只暴露必要的环境变量,避免安全风险
3838 'process.env.NODE_ENV' : JSON . stringify ( process . env . NODE_ENV || 'development' ) ,
3939 } ,
40+ build : {
41+ // 优化构建配置,避免 chunk 过大警告
42+ chunkSizeWarningLimit : 1000 ,
43+ rollupOptions : {
44+ output : {
45+ // 手动分割代码块,优化加载性能
46+ // 注意:检查顺序很重要,先检查具体的库,再检查通用的
47+ manualChunks : ( id ) => {
48+ // 国际化库(先检查,避免被 react 匹配)
49+ if ( id . includes ( 'i18next' ) || id . includes ( 'react-i18next' ) ) {
50+ return 'i18n-vendor' ;
51+ }
52+ // 数据获取库
53+ if ( id . includes ( 'swr' ) ) {
54+ return 'data-vendor' ;
55+ }
56+ // 工具库
57+ if ( id . includes ( 'lodash' ) ) {
58+ return 'utils-vendor' ;
59+ }
60+ // 日期处理库(moment 较大,单独分割)
61+ if ( id . includes ( 'moment' ) ) {
62+ return 'date-vendor' ;
63+ }
64+ // 动画库
65+ if ( id . includes ( 'motion' ) || id . includes ( 'framer-motion' ) ) {
66+ return 'animation-vendor' ;
67+ }
68+ // 图标库
69+ if ( id . includes ( 'lucide-react' ) ) {
70+ return 'icons-vendor' ;
71+ }
72+ // 拖拽库
73+ if ( id . includes ( '@dnd-kit' ) ) {
74+ return 'dnd-vendor' ;
75+ }
76+ // Radix UI 组件库
77+ if ( id . includes ( '@radix-ui' ) ) {
78+ return 'ui-vendor' ;
79+ }
80+ // React 核心库(放在后面,避免匹配到其他 react-* 包)
81+ // 匹配 react、react-dom 和 react-router 系列
82+ if (
83+ ( id . includes ( 'node_modules/react/' ) && ! id . includes ( 'react-' ) ) ||
84+ id . includes ( 'node_modules/react-dom/' ) ||
85+ id . includes ( 'node_modules/react-router' )
86+ ) {
87+ return 'react-vendor' ;
88+ }
89+ // node_modules 中的其他依赖
90+ if ( id . includes ( 'node_modules' ) ) {
91+ return 'vendor' ;
92+ }
93+ } ,
94+ } ,
95+ } ,
96+ } ,
4097 preview : {
4198 host : true ,
4299 port : 3001 ,
You can’t perform that action at this time.
0 commit comments