mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-09-18 03:39:58 +08:00
fix: 修复正式环境地址错误
This commit is contained in:
parent
79501a53f0
commit
050ab3e7ed
@ -56,7 +56,7 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'vite-auto-proxy',
|
name: 'vite-auto-proxy',
|
||||||
config(config: UserConfig, { command }: { mode: string, command: 'build' | 'serve' }) {
|
config(config: UserConfig, { mode, command }: { mode: string, command: 'build' | 'serve' }) {
|
||||||
// 只在开发环境(serve命令)时生成代理配置
|
// 只在开发环境(serve命令)时生成代理配置
|
||||||
const isDev = command === 'serve'
|
const isDev = command === 'serve'
|
||||||
|
|
||||||
@ -66,9 +66,11 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!enableProxy || !isDev) {
|
if (!enableProxy || !isDev) {
|
||||||
// 在非开发环境下,生成原始地址映射(path 和 rawPath 都是原始地址)
|
// 在非开发环境下,根据构建模式选择正确的环境配置
|
||||||
|
const targetEnv = isDev ? devEnvName : mode
|
||||||
const rawMapping: ProxyMapping = {}
|
const rawMapping: ProxyMapping = {}
|
||||||
const envConfig = serviceConfig[devEnvName]
|
const envConfig = serviceConfig[targetEnv]
|
||||||
|
|
||||||
if (envConfig) {
|
if (envConfig) {
|
||||||
Object.entries(envConfig).forEach(([serviceName, serviceUrl]) => {
|
Object.entries(envConfig).forEach(([serviceName, serviceUrl]) => {
|
||||||
rawMapping[serviceName] = {
|
rawMapping[serviceName] = {
|
||||||
@ -76,7 +78,12 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
|||||||
rawPath: serviceUrl,
|
rawPath: serviceUrl,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
console.warn(`[auto-proxy] 已加载 ${Object.keys(envConfig).length} 个服务地址`)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
console.warn(`[auto-proxy] 未找到环境 "${targetEnv}" 的配置`)
|
||||||
|
}
|
||||||
|
|
||||||
config.define[envName] = JSON.stringify(rawMapping)
|
config.define[envName] = JSON.stringify(rawMapping)
|
||||||
|
|
||||||
// 生成 d.ts 类型文件(如果指定了路径)
|
// 生成 d.ts 类型文件(如果指定了路径)
|
||||||
|
17
netlify.toml
17
netlify.toml
@ -1,17 +0,0 @@
|
|||||||
[build]
|
|
||||||
publish = "dist"
|
|
||||||
command = "vite build --mode prod"
|
|
||||||
|
|
||||||
[build.environment]
|
|
||||||
NODE_VERSION = "20"
|
|
||||||
|
|
||||||
[[redirects]]
|
|
||||||
from = "/*"
|
|
||||||
to = "/index.html"
|
|
||||||
status = 200
|
|
||||||
|
|
||||||
[[headers]]
|
|
||||||
for = "/manifest.webmanifest"
|
|
||||||
|
|
||||||
[headers.values]
|
|
||||||
Content-Type = "application/manifest+json"
|
|
@ -38,8 +38,8 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite --mode dev --port 9980",
|
"dev": "vite --mode dev --port 9980",
|
||||||
"dev:prod": "vite --mode prod",
|
"dev:prod": "vite --mode production",
|
||||||
"build": "vite build --mode prod",
|
"build": "vite build",
|
||||||
"build:dev": "vite build --mode dev",
|
"build:dev": "vite build --mode dev",
|
||||||
"preview": "vite preview --port 9981",
|
"preview": "vite preview --port 9981",
|
||||||
"lint": "eslint . && vue-tsc --noEmit",
|
"lint": "eslint . && vue-tsc --noEmit",
|
||||||
|
@ -3,7 +3,7 @@ export const serviceConfig: Record<ServiceEnvType, Record<string, string>> = {
|
|||||||
dev: {
|
dev: {
|
||||||
url: 'http://localhost:3000',
|
url: 'http://localhost:3000',
|
||||||
},
|
},
|
||||||
prod: {
|
production: {
|
||||||
url: 'https://mock.apifox.cn/m1/4071143-0-default',
|
url: 'https://mock.apifox.cn/m1/4071143-0-default',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
2
src/typings/env.d.ts
vendored
2
src/typings/env.d.ts
vendored
@ -3,7 +3,7 @@
|
|||||||
* - dev: 后台开发环境
|
* - dev: 后台开发环境
|
||||||
* - prod: 后台生产环境
|
* - prod: 后台生产环境
|
||||||
*/
|
*/
|
||||||
type ServiceEnvType = 'dev' | 'prod'
|
type ServiceEnvType = 'dev' | 'production'
|
||||||
|
|
||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
/** 项目基本地址 */
|
/** 项目基本地址 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user