-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
50 lines (43 loc) · 1.05 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
import { PluginOption, defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react-swc';
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': {},
},
server: {
host,
proxy,
port: +port,
},
};
});