import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react-swc' import path from 'path' // https://vite.dev/config/ export default defineConfig(({ mode }) => { const env = loadEnv(mode, path.resolve(process.cwd(), './'), '') // console.log('当前环境:', mode) // console.log('读取的.env变量:', env.VITE_WEB_BASE_URL) return { plugins: [react()], base: env.VITE_WEB_BASE_URL, build: { outDir: "../internal/web/api/static/www" }, server: { port: 5174, proxy: { // 代理所有 /api 请求到后端服务器 '/api': { target: 'http://127.0.0.1:8089', changeOrigin: true, secure: false, // 可选:重写路径 // rewrite: (path) => path.replace(/^\/api/, '') }, '/uploads': { target: 'http://127.0.0.1:8089', changeOrigin: true, secure: false, // 可选:重写路径 // rewrite: (path) => path.replace(/^\/api/, '') }, } } } })