forked from interval/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
72 lines (68 loc) · 2.15 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
import path from 'path'
import { defineConfig, HttpProxy, splitVendorChunkPlugin } from 'vite'
import react from '@vitejs/plugin-react'
import nodeResolve from '@rollup/plugin-node-resolve'
import postcss from './postcss.config'
import checker from 'vite-plugin-checker'
// https://vitejs.dev/config/
export default defineConfig(async ({ command }) => {
const mdx = await import('@mdx-js/rollup').then(r => r.default)
const rehypeHighlight = await import('rehype-highlight').then(r => r.default)
return {
define: {
'process.env.GIT_COMMIT': JSON.stringify(process.env.GIT_COMMIT),
},
plugins: [
react(),
mdx({ rehypePlugins: [rehypeHighlight], remarkPlugins: [] }),
nodeResolve(),
splitVendorChunkPlugin(),
command === 'build' ? checker({ typescript: true }) : undefined,
],
css: {
postcss,
},
server: {
host: process.env.VITE_HOST === 'true' ? true : process.env.VITE_HOST,
port: 3000,
proxy: {
'^/(api|health-check).*': {
target: `http://localhost:3001`,
changeOrigin: true,
configure: configureProxy,
},
'^/websocket': {
target: 'ws://localhost:3002',
changeOrigin: true,
configure: configureProxy,
},
},
watch: {
// prevent hot reloading when backend files change
ignored: ['**/src/server/**/*.ts', '**/env.ts', '**/entry.ts'],
},
},
resolve: {
alias: [
{ find: 'node-fetch', replacement: 'cross-fetch' },
{ find: '~', replacement: path.resolve(__dirname, './src') },
{ find: 'src', replacement: path.resolve(__dirname, './src') },
{ find: 'env', replacement: path.resolve(__dirname, './env') },
],
},
build: {
outDir: 'dist/client',
assetsDir: 'app-assets',
},
}
})
function configureProxy(proxy: HttpProxy.Server) {
proxy.removeAllListeners('error')
proxy.on('error', err => {
// experimental: silence ECONNREFUSED errors when Vite is ready but the backend hasn't started yet
if (err.message.includes('ECONNREFUSED 127.0.0.1')) {
return
}
console.error(err)
})
}