From 7db3de223c326b70f14a711a06d21c29124bec44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cls=5F=E5=AE=81=E6=B3=A2=E6=9C=AC=E6=9C=BA?= <908705107@qq.com> Date: Wed, 10 Jun 2026 14:00:32 +0800 Subject: [PATCH] Make web runtime scripts self contained --- web/apps/web-ele/package.json | 6 +++--- web/apps/web-ele/vite.config.mts | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) 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, }, },