-
Notifications
You must be signed in to change notification settings - Fork 17
/
vite.config.ts
93 lines (91 loc) · 2.32 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
import path from 'path';
import react from '@vitejs/plugin-react';
import svgr from 'vite-plugin-svgr';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
react(),
svgr(),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]',
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@@': path.resolve(__dirname, './examples'),
},
},
server: {
host: true,
port: 9527,
proxy: {
'/api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
esbuild: {
target: 'chrome65',
},
build: {
target: 'es2015',
rollupOptions: {
output: {
manualChunks(id/* , { getModuleInfo } */) {
const ret = resolveManualChunks(id, {
react: ['node_modules/react'],
vendor: ['node_modules/dayjs', 'node_modules/@ant', 'node_modules/antd'],
'framer-motion': ['node_modules/framer-motion'],
echarts: ['node_modules/echarts'],
svg: [
'src/assets/svg',
],
common: [
'main.tsx',
'App.tsx',
['src/router/', '!/config/'],
'src/layouts/',
'src/http/',
'src/lib/',
],
pages: [
'src/pages/',
],
});
return ret;
},
},
},
},
});
function resolveManualChunks(id: string, configs: Record<string, (string | string[])[]>): string | void {
for (const key in configs) {
const val = configs[key];
for (let i = 0; i < val.length; i++) {
const item = val[i];
if (typeof item === 'string') {
if (id.includes(item)) {
return key;
}
} else {
const condition = item.every(innerItem => {
if (innerItem.startsWith('!')) {
return !id.includes(innerItem.slice(1));
} else {
return id.includes(innerItem);
}
});
if (condition) {
return key;
}
}
}
}
}