fix: 環境變數讀取

This commit is contained in:
skytek_xinliang
2026-05-22 09:50:54 +08:00
parent b5bf2eb37e
commit 59d04a4d7e
2 changed files with 20 additions and 4 deletions
+13
View File
@@ -1,3 +1,16 @@
# vite / vite dev:預設 mode = development
# vite build:預設 mode = production
# vite --mode staging:改成 staging
# vite build --mode developmentbuild 但用 development mode
# 覆蓋優先從低至高
# .env
# .env.local
# .env.[mode]
# .env.[mode].local
# Vite dev proxy 目標後端 URL。 # Vite dev proxy 目標後端 URL。
VITE_PROXY_TARGET=http://192.168.89.54:9002 VITE_PROXY_TARGET=http://192.168.89.54:9002
+7 -4
View File
@@ -1,10 +1,13 @@
import { fileURLToPath, URL } from 'node:url' import { fileURLToPath, URL } from 'node:url'
import Vue from '@vitejs/plugin-vue' import Vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite' import { defineConfig, loadEnv } from 'vite'
import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify' import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
plugins: [ plugins: [
Vue({ Vue({
template: { transformAssetUrls }, template: { transformAssetUrls },
@@ -36,7 +39,7 @@ export default defineConfig({
port: 3700, port: 3700,
proxy:{ proxy:{
"/service/": { "/service/": {
target: process.env.VITE_PROXY_TARGET || "http://localhost:8080", target: env.VITE_PROXY_TARGET || "http://localhost:8080",
changeOrigin: true, changeOrigin: true,
}, },
} }
@@ -47,4 +50,4 @@ export default defineConfig({
}, },
}, },
}, },
}) }})