-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
38 lines (35 loc) · 1.23 KB
/
Copy pathvite.config.ts
File metadata and controls
38 lines (35 loc) · 1.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
import { defineConfig, type Plugin } from 'vite'
import react from '@vitejs/plugin-react'
// Safari drops idle WebSockets after ~60s and doesn't count protocol-level
// ping/pong as activity. Vite's HMR client unconditionally reloads the page
// on WS disconnect+reconnect, so a dropped WS = full page refresh. Send an
// application-level keepalive from the server every 25s to keep Safari's
// idle timer reset. 25s clears NAT/proxy 30s windows and stays under 60s.
function hmrKeepalive(): Plugin {
return {
name: 'hmr-keepalive',
apply: 'serve',
configureServer(server) {
const id = setInterval(() => {
server.ws.send({ type: 'custom', event: 'hmr:keepalive', data: {} })
}, 25_000)
server.httpServer?.once('close', () => clearInterval(id))
},
}
}
export default defineConfig({
plugins: [react(), hmrKeepalive()],
server: {
port: 3000,
host: true,
proxy: {
'/api': 'http://localhost:3001',
},
watch: {
// Jobs run inside .worktrees/* which contain full checkouts of the
// repo including src/. Without this, any file the task writes
// triggers HMR and a full page reload mid-task.
ignored: ['**/.worktrees/**', '**/supabase/.temp/**'],
},
},
})