41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { defineConfig } from 'vite'
|
||
import react from '@vitejs/plugin-react'
|
||
import path from 'path'
|
||
|
||
export default defineConfig({
|
||
plugins: [react()],
|
||
optimizeDeps: {
|
||
include: ['lucide-react'],
|
||
},
|
||
server: {
|
||
proxy: {
|
||
'/api': {
|
||
target: 'http://localhost:3001',
|
||
changeOrigin: true,
|
||
configure: (proxy) => {
|
||
proxy.on('error', () => {}) // 后端未启动时静默失败
|
||
},
|
||
},
|
||
'/ws': {
|
||
target: 'ws://localhost:3001',
|
||
ws: true,
|
||
changeOrigin: true,
|
||
configure: (proxy) => {
|
||
proxy.on('error', () => {}) // 后端未启动时静默失败
|
||
// 抑制关标签/刷新时代理底层 socket 的 ECONNRESET,避免刷屏
|
||
proxy.on('proxyReqWs', (proxyReq, req, socket, head) => {
|
||
socket?.on?.('error', () => {})
|
||
const out = (proxyReq as { socket?: { on?: (e: string, fn: () => void) => void } })?.socket
|
||
out?.on?.('error', () => {})
|
||
})
|
||
},
|
||
},
|
||
},
|
||
},
|
||
resolve: {
|
||
alias: {
|
||
'@': path.resolve(__dirname, './src'),
|
||
},
|
||
},
|
||
})
|