diff --git a/.env.example b/.env.example index 8575ca4..2ef9dd0 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,16 @@ +# vite / vite dev:預設 mode = development +# vite build:預設 mode = production +# vite --mode staging:改成 staging +# vite build --mode development:build 但用 development mode + +# 覆蓋優先從低至高 +# .env +# .env.local +# .env.[mode] +# .env.[mode].local + + + # Vite dev proxy 目標後端 URL。 VITE_PROXY_TARGET=http://192.168.89.54:9002 diff --git a/vite.config.mts b/vite.config.mts index c543b4b..7c88626 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -1,10 +1,13 @@ import { fileURLToPath, URL } from 'node:url' import Vue from '@vitejs/plugin-vue' -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import Vuetify, { transformAssetUrls } from 'vite-plugin-vuetify' // https://vitejs.dev/config/ -export default defineConfig({ +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), '') + + return { plugins: [ Vue({ template: { transformAssetUrls }, @@ -36,7 +39,7 @@ export default defineConfig({ port: 3700, proxy:{ "/service/": { - target: process.env.VITE_PROXY_TARGET || "http://localhost:8080", + target: env.VITE_PROXY_TARGET || "http://localhost:8080", changeOrigin: true, }, } @@ -47,4 +50,4 @@ export default defineConfig({ }, }, }, -}) +}})