Make web runtime scripts self contained

This commit is contained in:
2026-06-10 14:00:32 +08:00
parent f7970c8a57
commit 7db3de223c
2 changed files with 11 additions and 6 deletions
+3 -3
View File
@@ -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"
},
+8 -3
View File
@@ -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,
},
},