Files
video-factory/ui-src/vite.config.js
T
2026-08-05 08:53:43 +08:00

37 lines
1.1 KiB
JavaScript

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const target = env.VITE_API_PROXY_TARGET || 'http://localhost:3006'
// 浏览器导航页面请求(需要 SPA)vs API 调用(需要代理到后端)
const spaBypass = (req) => {
const accept = req.headers['accept'] || ''
if (accept.includes('text/html')) {
return '/index.html'
}
}
const proxyRules = ['/drama', '/agent', '/customer', '/payment', '/transaction', '/region', '/user', '/scene', '/character', '/prop', '/bgm', '/episode', '/generation', '/model-config', '/user-model-config']
const proxy = {}
for (const rule of proxyRules) {
proxy[rule] = { target, changeOrigin: true, bypass: spaBypass }
}
proxy['/workspace'] = { target, changeOrigin: true }
return {
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
port: 5173,
proxy
}
}
})