62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig({
|
|
plugins: [
|
|
react(),
|
|
...(process.env.BUNDLE_VISUALIZE
|
|
? [visualizer({ filename: 'dist/stats.json', template: 'raw-data', gzipSize: true })]
|
|
: []),
|
|
],
|
|
server: {
|
|
port: 3002,
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://localhost:3000',
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
build: {
|
|
// 稳定 vendor 分包:大库单独成 chunk,利于浏览器缓存与按需加载
|
|
rolldownOptions: {
|
|
output: {
|
|
codeSplitting: {
|
|
groups: [
|
|
{
|
|
name: (id) => {
|
|
if (!id.includes('node_modules')) return null;
|
|
// 只对体积大且相互独立的纯库手动分组;antd/markdown 栈
|
|
// 交给 rolldown 默认分包,避免人为制造超大 chunk。
|
|
if (/[\\/]node_modules[\\/](echarts|zrender)[\\/]/.test(id)) return 'echarts';
|
|
if (/[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom|scheduler|use-sync-external-store)[\\/]/.test(id)) return 'react';
|
|
if (/[\\/]node_modules[\\/]dayjs[\\/]/.test(id)) return 'dayjs';
|
|
if (/[\\/]node_modules[\\/]@tanstack[\\/]/.test(id)) return 'tanstack';
|
|
return null;
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
// 剩余大 chunk 均为按需加载(AI 绘图/ECharts 等),阈值按实际调高避免误报
|
|
chunkSizeWarningLimit: 700,
|
|
},
|
|
optimizeDeps: {
|
|
include: [
|
|
'dayjs',
|
|
'dayjs/locale/zh-cn',
|
|
'dayjs/plugin/customParseFormat',
|
|
'dayjs/plugin/advancedFormat',
|
|
'dayjs/plugin/weekday',
|
|
'dayjs/plugin/localeData',
|
|
'dayjs/plugin/weekOfYear',
|
|
'dayjs/plugin/weekYear',
|
|
'dayjs/plugin/updateLocale',
|
|
'antd/es/locale/zh_CN',
|
|
],
|
|
},
|
|
});
|