mirror of
https://github.com/chansee97/nova-admin.git
synced 2026-07-07 18:11:09 +08:00
Compare commits
2 Commits
79501a53f0
...
ac9d7e84e5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac9d7e84e5 | ||
|
|
050ab3e7ed |
@ -38,7 +38,7 @@ export interface ServiceProxyPluginOptions {
|
||||
devEnvName?: ServiceEnvType
|
||||
/** 是否启用代理配置 */
|
||||
enableProxy?: boolean
|
||||
/** 环境变量名(可选,默认为 '__PROXY_MAPPING__') */
|
||||
/** 环境变量名(可选,默认为 '__URL_MAP__') */
|
||||
envName?: string
|
||||
/** d.ts 类型文件生成路径(可选,如果传入路径则在该路径生成 d.ts 类型文件) */
|
||||
dts?: string
|
||||
@ -50,13 +50,13 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
||||
devEnvName = 'development',
|
||||
proxyPrefix = 'proxy-',
|
||||
enableProxy = true,
|
||||
envName = '__PROXY_MAPPING__',
|
||||
envName = '__URL_MAP__',
|
||||
dts,
|
||||
} = options
|
||||
|
||||
return {
|
||||
name: 'vite-auto-proxy',
|
||||
config(config: UserConfig, { command }: { mode: string, command: 'build' | 'serve' }) {
|
||||
config(config: UserConfig, { mode, command }: { mode: string, command: 'build' | 'serve' }) {
|
||||
// 只在开发环境(serve命令)时生成代理配置
|
||||
const isDev = command === 'serve'
|
||||
|
||||
@ -66,9 +66,11 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
||||
}
|
||||
|
||||
if (!enableProxy || !isDev) {
|
||||
// 在非开发环境下,生成原始地址映射(path 和 rawPath 都是原始地址)
|
||||
// 在非开发环境下,根据构建模式选择正确的环境配置
|
||||
const targetEnv = isDev ? devEnvName : mode
|
||||
const rawMapping: ProxyMapping = {}
|
||||
const envConfig = serviceConfig[devEnvName]
|
||||
const envConfig = serviceConfig[targetEnv]
|
||||
|
||||
if (envConfig) {
|
||||
Object.entries(envConfig).forEach(([serviceName, serviceUrl]) => {
|
||||
rawMapping[serviceName] = {
|
||||
@ -76,7 +78,12 @@ export default function createServiceProxyPlugin(options: ServiceProxyPluginOpti
|
||||
rawPath: serviceUrl,
|
||||
}
|
||||
})
|
||||
console.warn(`[auto-proxy] 已加载 ${Object.keys(envConfig).length} 个服务地址`)
|
||||
}
|
||||
else {
|
||||
console.warn(`[auto-proxy] 未找到环境 "${targetEnv}" 的配置`)
|
||||
}
|
||||
|
||||
config.define[envName] = JSON.stringify(rawMapping)
|
||||
|
||||
// 生成 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": {
|
||||
"dev": "vite --mode dev --port 9980",
|
||||
"dev:prod": "vite --mode prod",
|
||||
"build": "vite build --mode prod",
|
||||
"dev:prod": "vite --mode production",
|
||||
"build": "vite build",
|
||||
"build:dev": "vite build --mode dev",
|
||||
"preview": "vite preview --port 9981",
|
||||
"lint": "eslint . && vue-tsc --noEmit",
|
||||
|
||||
@ -3,7 +3,7 @@ export const serviceConfig: Record<ServiceEnvType, Record<string, string>> = {
|
||||
dev: {
|
||||
url: 'http://localhost:3000',
|
||||
},
|
||||
prod: {
|
||||
production: {
|
||||
url: 'https://mock.apifox.cn/m1/4071143-0-default',
|
||||
},
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { createAlovaInstance } from './alova'
|
||||
|
||||
export const request = createAlovaInstance({
|
||||
baseURL: __PROXY_MAPPING__.url.path,
|
||||
baseURL: __URL_MAP__.url.path,
|
||||
})
|
||||
|
||||
export const blankInstance = createAlovaInstance({
|
||||
|
||||
2
src/typings/env.d.ts
vendored
2
src/typings/env.d.ts
vendored
@ -3,7 +3,7 @@
|
||||
* - dev: 后台开发环境
|
||||
* - prod: 后台生产环境
|
||||
*/
|
||||
type ServiceEnvType = 'dev' | 'prod'
|
||||
type ServiceEnvType = 'dev' | 'production'
|
||||
|
||||
interface ImportMetaEnv {
|
||||
/** 项目基本地址 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user