-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
67 lines (65 loc) · 1.68 KB
/
vite.config.js
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
import { loadEnv } from 'vite';
import reactRefresh from '@vitejs/plugin-react-refresh';
import path from 'path';
import styleImport from 'vite-plugin-style-import';
// https://vitejs.dev/config/
export default ({ command, mode }) => {
const root = process.cwd();
const env = loadEnv(mode, root);
// 拿到的值是 string 类型
const { VITE_PORT, VITE_HTTP_API } = env;
return {
plugins: [
reactRefresh(),
// styleImport
styleImport({
libs: [
{
libraryName: 'antd',
esModule: true,
resolveStyle: (name) => {
return `antd/es/${name}/style/index`;
},
},
],
}),
],
css: {
preprocessorOptions: {
less: {
// 支持内联 JavaScript,支持 less 内联 JS
javascriptEnabled: true,
},
},
},
resolve: {
alias: [
{ find: /^~/, replacement: path.resolve(__dirname, './') },
{ find: '@', replacement: path.resolve(__dirname, 'src') },
],
},
server: {
port: Number(VITE_PORT), // 开发环境启动的端口
proxy: {
'/api': {
// 当遇到 /api 路径时,将其转换成 target 的值
target: VITE_HTTP_API,
changeOrigin: true,
// rewrite: (pre) => pre.replace(/^\/api/, ''), // 将 /api 重写为空
},
},
},
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString();
}
return 'wq';
},
},
},
},
}
}