-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
88 lines (75 loc) · 2.33 KB
/
Copy pathvite.config.ts
File metadata and controls
88 lines (75 loc) · 2.33 KB
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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import react from '@vitejs/plugin-react';
import { defineConfig, loadEnv } from 'vite';
const dirname = path.dirname(fileURLToPath(import.meta.url));
const defaultBe1ProxyTarget = 'http://localhost:8081';
const defaultBe3ProxyTarget = 'http://localhost:8083';
function resolveDevProxyTarget(rawValue: string | undefined, fallback: string): string {
const value = rawValue?.trim();
if (!value || value.startsWith('/')) {
return fallback;
}
return value;
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const be1ProxyTarget = resolveDevProxyTarget(env.VITE_BE1_BASE_URL, defaultBe1ProxyTarget);
const be3ProxyTarget = resolveDevProxyTarget(env.VITE_BE3_BASE_URL, defaultBe3ProxyTarget);
return {
build: {
rollupOptions: {
output: {
manualChunks(id) {
const normalizedId = id.replaceAll(path.sep, '/');
if (!normalizedId.includes('/node_modules/')) {
return;
}
if (
normalizedId.includes('/antd/') ||
normalizedId.includes('/@ant-design/') ||
normalizedId.includes('/rc-')
) {
return 'antd';
}
if (
normalizedId.includes('/react/') ||
normalizedId.includes('/react-dom/') ||
normalizedId.includes('/scheduler/')
) {
return 'react';
}
if (normalizedId.includes('/@tanstack/')) {
return 'router';
}
if (normalizedId.includes('/zustand/')) {
return 'state';
}
return;
},
},
},
},
plugins: [react(), vanillaExtractPlugin()],
resolve: {
alias: {
'@': path.resolve(dirname, 'src'),
},
},
server: {
proxy: {
'/be1': {
changeOrigin: true,
rewrite: (requestPath) => requestPath.replace(/^\/be1/u, ''),
target: be1ProxyTarget,
},
'/be3': {
changeOrigin: true,
rewrite: (requestPath) => requestPath.replace(/^\/be3/u, ''),
target: be3ProxyTarget,
},
},
},
};
});