90 lines
1.8 KiB
TypeScript
90 lines
1.8 KiB
TypeScript
/**
|
|
* 性能优化配置
|
|
*/
|
|
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import path from 'path';
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [
|
|
react({
|
|
// 开启 Fast Refresh
|
|
fastRefresh: true,
|
|
// Babel 配置
|
|
babel: {
|
|
plugins: [
|
|
// 按需加载 Ant Design
|
|
['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
},
|
|
},
|
|
server: {
|
|
port: 3000,
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://localhost:8000',
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
// HMR 优化
|
|
hmr: {
|
|
overlay: true,
|
|
},
|
|
},
|
|
build: {
|
|
// 代码分割优化
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
// React 核心库
|
|
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
|
|
// Ant Design
|
|
'antd-vendor': ['antd', '@ant-design/icons'],
|
|
// 状态管理和数据获取
|
|
'state-vendor': ['zustand', '@tanstack/react-query', 'axios'],
|
|
},
|
|
},
|
|
},
|
|
// 压缩优化
|
|
minify: 'terser',
|
|
terserOptions: {
|
|
compress: {
|
|
drop_console: true, // 生产环境移除 console
|
|
drop_debugger: true,
|
|
},
|
|
},
|
|
// 生成 source map
|
|
sourcemap: false,
|
|
// chunk 大小警告限制
|
|
chunkSizeWarningLimit: 1000,
|
|
},
|
|
// CSS 优化
|
|
css: {
|
|
preprocessorOptions: {
|
|
less: {
|
|
javascriptEnabled: true,
|
|
},
|
|
},
|
|
},
|
|
// 依赖优化
|
|
optimizeDeps: {
|
|
include: [
|
|
'react',
|
|
'react-dom',
|
|
'react-router-dom',
|
|
'antd',
|
|
'@ant-design/icons',
|
|
'zustand',
|
|
'@tanstack/react-query',
|
|
'axios',
|
|
],
|
|
},
|
|
});
|