优化vite配置文件
This commit is contained in:
parent
d27cb3d4ca
commit
1cbedb3420
@ -1,5 +0,0 @@
|
|||||||
## 前端环境变量 (Vite会读取VITE_前缀的变量)
|
|
||||||
# 开发环境:前端使用相对路径,通过Vite代理转发
|
|
||||||
# 生产环境:前端直接请求后端服务器
|
|
||||||
VITE_JINGROW_SERVER_URL=
|
|
||||||
VITE_BACKEND_SERVER_URL=
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
import { fileURLToPath, URL } from 'node:url'
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
@ -27,7 +27,12 @@ const currentDir = fileURLToPath(new URL('.', import.meta.url))
|
|||||||
const appsDir = path.resolve(currentDir, '..', '..')
|
const appsDir = path.resolve(currentDir, '..', '..')
|
||||||
const APPS_ORDER = loadAppsOrder(appsDir)
|
const APPS_ORDER = loadAppsOrder(appsDir)
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig(({ mode }) => {
|
||||||
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
|
const JINGROW_SERVER_URL = env.VITE_JINGROW_SERVER_URL
|
||||||
|
const BACKEND_URL = env.VITE_BACKEND_SERVER_URL
|
||||||
|
|
||||||
|
return {
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
Icons({
|
Icons({
|
||||||
@ -62,17 +67,17 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api/action': {
|
'/api/action': {
|
||||||
target: process.env.VITE_JINGROW_SERVER_URL || 'https://simon.c1.site.jingrow.com',
|
target: JINGROW_SERVER_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false
|
secure: false
|
||||||
},
|
},
|
||||||
'/api/data': {
|
'/api/data': {
|
||||||
target: process.env.VITE_BACKEND_SERVER_URL || 'http://localhost:9001',
|
target: BACKEND_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false
|
secure: false
|
||||||
},
|
},
|
||||||
'/jingrow': {
|
'/jingrow': {
|
||||||
target: process.env.VITE_BACKEND_SERVER_URL || 'http://localhost:9001',
|
target: BACKEND_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
secure: false
|
secure: false
|
||||||
}
|
}
|
||||||
@ -88,4 +93,5 @@ export default defineConfig({
|
|||||||
// 注入 apps.txt 的应用顺序到前端
|
// 注入 apps.txt 的应用顺序到前端
|
||||||
__APPS_ORDER__: JSON.stringify(APPS_ORDER)
|
__APPS_ORDER__: JSON.stringify(APPS_ORDER)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user