Files
badminton-scoreboard/vite.config.ts
T
JianMiau 304bcaeedd 修正:dev 環境改善(vite 對網路磁碟啟用 polling、Service Worker 僅正式版註冊)
摘要:
- vite dev server 啟用 watch.usePolling,讓 W: 網路磁碟(RaiDrive)的檔案變更能觸發 HMR
- Service Worker 改為僅在正式版(import.meta.env.PROD)才註冊,dev 不再註冊

根本原因:
- 專案放在 RaiDrive 掛載的網路磁碟,不會發出 fs 事件,vite 預設的檔案監看抓不到變更,HMR 失效
- dev 也註冊 SW 會用快取卡住舊版 bundle,改了程式看不到效果

影響:
- vite.config.ts:server.watch 加上 usePolling 與 interval
- src/main.tsx:SW 註冊條件加上 import.meta.env.PROD

修法:
- 開發時靠 polling 監看檔案;SW 只在 build 後的正式環境啟用

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 17:42:22 +08:00

20 lines
432 B
TypeScript

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 3501,
strictPort: true,
// W: 是 RaiDrive 網路磁碟,不會發 fs 事件,需用 polling 才能觸發 HMR
watch: {
usePolling: true,
interval: 300,
},
proxy: {
'/api': 'http://127.0.0.1:8788',
},
},
})