feat: fund-mobile支持Nginx子路径/fmobile部署
- 新增.env.development/.env.production环境配置 - vite.config.ts支持VITE_BASE动态base路径 - router使用import.meta.env.BASE_URL - API baseURL使用环境变量 - 新增vite-env.d.ts类型声明
This commit is contained in:
parent
bd5f8ab468
commit
1a5b583c2f
6
fund-mobile/.env.development
Normal file
6
fund-mobile/.env.development
Normal file
@ -0,0 +1,6 @@
|
||||
# 开发环境配置
|
||||
# 开发模式无部署前缀
|
||||
VITE_BASE=/
|
||||
|
||||
# API基础路径(开发模式使用代理)
|
||||
VITE_API_BASE_URL=
|
||||
6
fund-mobile/.env.production
Normal file
6
fund-mobile/.env.production
Normal file
@ -0,0 +1,6 @@
|
||||
# 生产环境配置
|
||||
# 部署路径前缀(Nginx路由使用)
|
||||
VITE_BASE=/fmobile/
|
||||
|
||||
# API基础路径
|
||||
VITE_API_BASE_URL=/fund
|
||||
@ -1,7 +1,7 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const request = axios.create({
|
||||
baseURL: '/fund',
|
||||
baseURL: import.meta.env.VITE_API_BASE_URL || '/fund',
|
||||
timeout: 15000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
||||
@ -2,7 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { useTenantStore } from '@/stores/tenant'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
|
||||
10
fund-mobile/src/vite-env.d.ts
vendored
Normal file
10
fund-mobile/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_BASE: string
|
||||
readonly VITE_API_BASE_URL: string
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv
|
||||
}
|
||||
@ -1,47 +1,55 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import Components from 'unplugin-vue-components/vite'
|
||||
import { VantResolver } from '@vant/auto-import-resolver'
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
Components({
|
||||
resolvers: [VantResolver()]
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
server: {
|
||||
port: 8080,
|
||||
proxy: {
|
||||
'/sys': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/cust': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/proj': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/exp': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/receipt': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/file': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
export default defineConfig(({ mode }) => {
|
||||
// 加载环境变量
|
||||
const env = loadEnv(mode, process.cwd())
|
||||
const base = env.VITE_BASE || '/'
|
||||
|
||||
return {
|
||||
// 部署路径前缀
|
||||
base,
|
||||
plugins: [
|
||||
vue(),
|
||||
Components({
|
||||
resolvers: [VantResolver()]
|
||||
})
|
||||
],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
}
|
||||
},
|
||||
server: {
|
||||
port: 8080,
|
||||
proxy: {
|
||||
'/sys': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/cust': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/proj': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/exp': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/receipt': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
},
|
||||
'/file': {
|
||||
target: 'http://localhost:8000',
|
||||
changeOrigin: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user