-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathvite.config.ts
129 lines (118 loc) · 3.01 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { defineConfig, loadEnv, UserConfigExport } from 'vite';
import react from '@vitejs/plugin-react-swc';
import tsconfigPaths from 'vite-tsconfig-paths';
import { ViteEjsPlugin } from 'vite-plugin-ejs';
import checker from 'vite-plugin-checker';
import { IncomingMessage } from 'http';
export default defineConfig(({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
const isDevMode = mode === 'development';
const isProxy = process.env.VITE_DEV_PROXY;
const defaultPlugins = [
react(),
tsconfigPaths(),
ViteEjsPlugin({
PUBLIC_PATH: !isDevMode ? 'PUBLIC-PATH-VARIABLE' : '',
}),
];
const prodPlugins = [...defaultPlugins];
const devPlugins = [
...defaultPlugins,
checker({
overlay: { initialIsOpen: false },
typescript: true,
eslint: { lintCommand: 'eslint --ext .tsx,.ts src/' },
}),
];
const defaultConfig: UserConfigExport = {
plugins: isDevMode ? devPlugins : prodPlugins,
server: {
port: 3000,
},
build: {
outDir: 'build/vite',
rollupOptions: {
output: {
manualChunks(id: string) {
if (id.includes('ace-builds') || id.includes('react-ace')) {
return 'ace';
}
// creating a chunk to react routes deps. Reducing the vendor chunk size
if (
id.includes('react-router-dom') ||
id.includes('@remix-run') ||
id.includes('react-router')
) {
return '@react-router';
}
return null;
},
},
},
},
experimental: {
renderBuiltUrl(
filename: string,
{
hostType,
}: {
hostId: string;
hostType: 'js' | 'css' | 'html';
type: 'asset' | 'public';
}
) {
if (hostType === 'js') {
return {
runtime: `window.__assetsPathBuilder(${JSON.stringify(filename)})`,
};
}
return filename;
},
},
define: {
'process.env.NODE_ENV': `"${mode}"`,
'process.env.VITE_TAG': `"${process.env.VITE_TAG}"`,
'process.env.VITE_COMMIT': `"${process.env.VITE_COMMIT}"`,
},
};
const proxyDevServerConfig = {
...defaultConfig.server,
open: true,
proxy: {
'/login': {
target: isProxy,
changeOrigin: true,
secure: false,
bypass: (req: IncomingMessage) => {
if (req.method === 'GET') {
return req.url;
}
},
},
'/logout': {
target: isProxy,
changeOrigin: true,
secure: false,
},
'/api': {
target: isProxy,
changeOrigin: true,
secure: false,
},
'/actuator/info': {
target: isProxy,
changeOrigin: true,
secure: false,
},
},
};
if (isDevMode && isProxy) {
return {
...defaultConfig,
server: {
...proxyDevServerConfig,
},
};
}
return defaultConfig;
});