-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
114 lines (112 loc) · 3.19 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Agent } from 'node:https'
import { resolve } from 'node:path'
import react from '@vitejs/plugin-react'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'
import UnoCSS from 'unocss/vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { initGlobalLessVaribles } from './src/theme/initLessVar.js'
export function generateModifyVars(): any {
return {
...initGlobalLessVaribles,
// reference: Avoid repeated references
hack: `true; @import (reference) "${resolve('src/style/config.less')}";`,
}
}
// https://vitejs.dev/config/
export default defineConfig({
base: './',
esbuild: {
// drop: ['console', 'debugger'],
},
css: {
// 开css sourcemap方便找css
devSourcemap: true,
preprocessorOptions: {
less: {
modifyVars: generateModifyVars(),
javascriptEnabled: true,
},
},
},
json: {
namedExports: true,
stringify: true,
},
define: {},
plugins: [
UnoCSS(),
react(),
// 同步tsconfig.json的path设置alias
tsconfigPaths(),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [resolve('src/assets/icons')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]',
}),
visualizer({
open: false,
gzipSize: true,
brotliSize: true,
}),
],
server: {
// 自动打开浏览器
open: true,
host: true,
port: 8000,
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
// https://github.com/vitejs/vite/discussions/8998#discussioncomment-4408695
agent: new Agent({ keepAlive: true, keepAliveMsecs: 20000 }),
},
'/file': {
target: 'http://localhost:9000',
changeOrigin: true,
rewrite: path => path.replace(/^\/file/, ''),
// https://github.com/vitejs/vite/discussions/8998#discussioncomment-4408695
agent: new Agent({ keepAlive: true, keepAliveMsecs: 20000 }),
},
'/ws': {
target: 'ws://localhost:7000',
changeOrigin: true,
ws: true,
rewrite: path => path.replace(/^\/ws/, ''),
// https://github.com/vitejs/vite/discussions/8998#discussioncomment-4408695
agent: new Agent({ keepAlive: true, keepAliveMsecs: 20000 }),
},
},
},
optimizeDeps: {
include: ['react', 'react-dom', 'react-router-dom', 'antd'],
},
build: {
target: 'esnext',
minify: 'esbuild',
sourcemap: false,
cssCodeSplit: true,
chunkSizeWarningLimit: 1000, // 提高警告阈值到 1000 KB
rollupOptions: {
output: {
manualChunks: {
'vendor-react': ['react', 'react-dom', 'react-router-dom'],
'vendor-antd': ['antd', '@ant-design/icons', '@ant-design/cssinjs'],
'vendor-utils': ['axios', 'dayjs', 'i18next', 'zustand'],
'vendor-ui': ['framer-motion', 'styled-components', '@iconify/react'],
},
},
},
terserOptions: {
compress: {
// 生产环境移除console
drop_console: true,
drop_debugger: true,
},
},
},
})