Files
BiliNote/BillNote_frontend/vite.config.ts
Yang Han 6d077a4ed3 Update vite.config.ts
Modify to allow access from all domains
2025-07-17 01:29:59 +08:00

40 lines
1.0 KiB
TypeScript

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
import tailwindcss from '@tailwindcss/vite'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd() + '/../')
const apiBaseUrl = env.VITE_API_BASE_URL || 'http://localhost:8000'
const port = parseInt(env.VITE_FRONTEND_PORT || '3015', 10)
return {
base: './',
plugins: [react(), tailwindcss()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
host: '0.0.0.0',
port: port,
allowedHosts: true, // 允许任意域名访问
proxy: {
'/api': {
target: apiBaseUrl,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '/api'),
},
'/static': {
target: apiBaseUrl,
changeOrigin: true,
rewrite: path => path.replace(/^\/static/, '/static'),
},
},
},
}
})