fix: 移除其他模板

This commit is contained in:
2026-07-08 15:56:59 +08:00
parent 2a1a049e9d
commit d5b32e3849
3 changed files with 66 additions and 11 deletions

View File

@@ -4,7 +4,7 @@ VITE_PORT=5999
VITE_BASE=/
# 请求路径
VITE_BASE_URL=http://127.0.0.1:48080
VITE_BASE_URL=http://192.168.10.14:48080
# 接口地址
VITE_GLOB_API_URL=/admin-api
# 文件上传类型server - 后端上传, client - 前端直连上传仅支持S3服务

View File

@@ -1,20 +1,33 @@
import { loadEnv } from 'vite';
import { defineConfig } from '@vben/vite-config';
export default defineConfig(async () => {
// @ts-ignore
export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, process.cwd(), 'VITE_');
const baseUrl = env.VITE_BASE_URL || 'http://localhost:48080';
const apiUrl = env.VITE_GLOB_API_URL || '/admin-api';
// 如果 apiUrl 已经是完整 URL如生产环境不需要 proxy
// 开发环境 apiUrl 为相对路径(如 /admin-api通过 proxy 转发
const isFullUrl = /^https?:\/\//.test(apiUrl);
return {
application: {},
vite: {
server: {
allowedHosts: true,
proxy: {
'/admin-api': {
changeOrigin: true,
rewrite: (path) => path.replace(/^\/admin-api/, ''),
// mock代理目标地址
target: 'http://localhost:48080/admin-api',
ws: true,
},
},
proxy: isFullUrl
? {}
: {
[apiUrl]: {
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^${apiUrl}`), ''),
// 代理目标地址,从环境变量 VITE_BASE_URL + VITE_GLOB_API_URL 拼接
target: `${baseUrl}${apiUrl}`,
ws: true,
},
},
},
},
};