更新前端项目

This commit is contained in:
2025-11-17 16:49:03 +08:00
parent 638e152cff
commit 033890742d
16 changed files with 862 additions and 130 deletions

View File

@@ -1,4 +1,4 @@
import { defineConfig, type Plugin } from 'vite'
import { defineConfig, type Plugin, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import fs from 'fs'
@@ -47,7 +47,12 @@ function modelsManifestPlugin(): Plugin {
}
}
export default defineConfig({
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const apiBaseUrl = env.VITE_API_BASE_URL || 'http://localhost:3000'
const backendOrigin = apiBaseUrl.replace(/\/+$/, '')
return {
plugins: [
vue(),
modelsManifestPlugin(),
@@ -228,7 +233,7 @@ export default defineConfig({
},
// API代理转发到后端服务器
'/api': {
target: 'http://localhost:8000',
target: backendOrigin,
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/api/, '/api'),
@@ -267,7 +272,7 @@ export default defineConfig({
},
// 媒体文件代理转发到后端服务器
'/media': {
target: 'http://localhost:8000',
target: backendOrigin,
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/media/, '/media'),
@@ -308,7 +313,7 @@ export default defineConfig({
},
define: {
// 环境变量定义,确保在没有.env文件时也能正常工作
__VITE_API_BASE_URL__: JSON.stringify('http://localhost:8000/api'),
__VITE_API_BASE_URL__: JSON.stringify(`${backendOrigin}/api`),
__VITE_APP_TITLE__: JSON.stringify('Hertz Admin'),
__VITE_APP_VERSION__: JSON.stringify('1.0.0'),
},
@@ -324,4 +329,5 @@ export default defineConfig({
},
},
},
}
})