diff --git a/web/apps/web-ele/package.json b/web/apps/web-ele/package.json index 0cc431e..64747a6 100644 --- a/web/apps/web-ele/package.json +++ b/web/apps/web-ele/package.json @@ -16,9 +16,9 @@ }, "type": "module", "scripts": { - "build": "pnpm vite build --mode production", - "build:analyze": "pnpm vite build --mode analyze", - "dev": "pnpm vite --mode development", + "build": "vite build --mode production", + "build:analyze": "vite build --mode analyze", + "dev": "vite --mode development", "preview": "vite preview", "typecheck": "vue-tsc --noEmit --skipLibCheck" }, diff --git a/web/apps/web-ele/vite.config.mts b/web/apps/web-ele/vite.config.mts index 9696c08..b35f17f 100644 --- a/web/apps/web-ele/vite.config.mts +++ b/web/apps/web-ele/vite.config.mts @@ -3,16 +3,21 @@ import { defineConfig } from '@vben/vite-config'; import { fileURLToPath, URL } from 'node:url'; import ElementPlus from 'unplugin-element-plus/vite'; +import { loadEnv } from 'vite'; const resolveLocal = (path: string) => fileURLToPath(new URL(path, import.meta.url)); +const appDir = fileURLToPath(new URL('.', import.meta.url)); const exactAlias = (find: string, path: string) => ({ find: new RegExp(`^${find.replaceAll('/', '\\/')}$`), replacement: resolveLocal(path), }); -export default defineConfig(async () => { +export default defineConfig(async (config) => { + const env = loadEnv(config.mode, appDir); + const proxyTarget = env.VITE_PROXY_TARGET || 'http://localhost:8000'; + return { application: { injectMetadata: false, @@ -170,12 +175,12 @@ export default defineConfig(async () => { '/basic-api': { changeOrigin: true, rewrite: (path) => path.replace(/^\/basic-api/, ''), - target: 'http://localhost:8000', + target: proxyTarget, ws: true, }, '/ws': { changeOrigin: true, - target: 'ws://localhost:8000', + target: proxyTarget.replace(/^http/, 'ws'), ws: true, }, },