-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
58 lines (50 loc) · 1.31 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
import { PluginOption, defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react-swc';
import importMetaUrlPlugin from '@ws-ui/vite-plugins/dist/esbuild-plugin-import-meta-url';
const isDevEnv = process.env.NODE_ENV === 'development';
import { initProxy } from './proxy.config';
const redirect = (opts: { from: string; to: string }): PluginOption => {
return {
name: 'redirect',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url.startsWith(opts.from)) {
res.statusCode = 307;
res.setHeader('Location', opts.to);
res.setHeader('Content-Length', '0');
return res.end();
}
return next();
});
},
};
};
// https://vitejs.dev/config/
export default defineConfig(({ mode = 'local' }) => {
const env = loadEnv(mode, process.cwd(), '');
const port = env.PORT || 5001;
const host = env.HOST || '0.0.0.0';
const proxy = initProxy(env);
return {
plugins: [
react(),
redirect({
from: '/studio/',
to: '/',
}),
],
define: {
'process.env': {},
},
optimizeDeps: {
esbuildOptions: {
plugins: isDevEnv ? [importMetaUrlPlugin] : [],
},
},
server: {
host,
proxy,
port: +port,
},
};
});