-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathvite.config.ts
More file actions
76 lines (72 loc) · 2.23 KB
/
vite.config.ts
File metadata and controls
76 lines (72 loc) · 2.23 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
import { defineConfig, loadEnv } from 'vite'
import type { HttpProxy } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import { fileURLToPath } from 'url'
import { getNetworkHost } from './server/get-network-host.js'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
/** Suppress ECONNREFUSED proxy errors during startup (server not ready yet). */
function silenceStartupErrors(proxy: HttpProxy.Server) {
proxy.on('error', (err, _req, res) => {
if ('code' in err && err.code === 'ECONNREFUSED' && 'writeHead' in res) {
res.writeHead(503)
res.end()
}
})
}
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, __dirname, '')
const backendPort = env.PORT || '3001'
const backendHost = env.VITE_BACKEND_HOST || env.BACKEND_HOST || '127.0.0.1'
const backendUrl = `http://${backendHost}:${backendPort}`
const vitePort = parseInt(env.VITE_PORT || '5173', 10)
const allowedHosts = env.VITE_ALLOWED_HOSTS
? env.VITE_ALLOWED_HOSTS.split(',').map((h) => h.trim()).filter(Boolean)
: undefined // Vite's default behavior (localhost + host value)
return {
plugins: [react()],
define: {
__PERF_LOGGING__: JSON.stringify(env.PERF_LOGGING || ''),
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@test': path.resolve(__dirname, './test'),
'@shared': path.resolve(__dirname, './shared'),
},
},
build: {
outDir: 'dist/client',
sourcemap: mode === 'development',
chunkSizeWarningLimit: 1400,
},
server: {
host: getNetworkHost(),
allowedHosts,
port: vitePort,
watch: {
ignored: ['**/.worktrees/**', '**/.claude/worktrees/**', '**/demo-projects/**'],
},
proxy: {
'/api': {
target: backendUrl,
xfwd: true,
configure: silenceStartupErrors,
},
'/local-file': {
target: backendUrl,
xfwd: true,
configure: silenceStartupErrors,
},
'/ws': {
target: backendUrl,
ws: true,
changeOrigin: true,
xfwd: true,
configure: silenceStartupErrors,
},
},
},
}
})