Make web runtime scripts self contained
This commit is contained in:
@@ -16,9 +16,9 @@
|
|||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "pnpm vite build --mode production",
|
"build": "vite build --mode production",
|
||||||
"build:analyze": "pnpm vite build --mode analyze",
|
"build:analyze": "vite build --mode analyze",
|
||||||
"dev": "pnpm vite --mode development",
|
"dev": "vite --mode development",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"typecheck": "vue-tsc --noEmit --skipLibCheck"
|
"typecheck": "vue-tsc --noEmit --skipLibCheck"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,16 +3,21 @@ import { defineConfig } from '@vben/vite-config';
|
|||||||
import { fileURLToPath, URL } from 'node:url';
|
import { fileURLToPath, URL } from 'node:url';
|
||||||
|
|
||||||
import ElementPlus from 'unplugin-element-plus/vite';
|
import ElementPlus from 'unplugin-element-plus/vite';
|
||||||
|
import { loadEnv } from 'vite';
|
||||||
|
|
||||||
const resolveLocal = (path: string) =>
|
const resolveLocal = (path: string) =>
|
||||||
fileURLToPath(new URL(path, import.meta.url));
|
fileURLToPath(new URL(path, import.meta.url));
|
||||||
|
const appDir = fileURLToPath(new URL('.', import.meta.url));
|
||||||
|
|
||||||
const exactAlias = (find: string, path: string) => ({
|
const exactAlias = (find: string, path: string) => ({
|
||||||
find: new RegExp(`^${find.replaceAll('/', '\\/')}$`),
|
find: new RegExp(`^${find.replaceAll('/', '\\/')}$`),
|
||||||
replacement: resolveLocal(path),
|
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 {
|
return {
|
||||||
application: {
|
application: {
|
||||||
injectMetadata: false,
|
injectMetadata: false,
|
||||||
@@ -170,12 +175,12 @@ export default defineConfig(async () => {
|
|||||||
'/basic-api': {
|
'/basic-api': {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/basic-api/, ''),
|
rewrite: (path) => path.replace(/^\/basic-api/, ''),
|
||||||
target: 'http://localhost:8000',
|
target: proxyTarget,
|
||||||
ws: true,
|
ws: true,
|
||||||
},
|
},
|
||||||
'/ws': {
|
'/ws': {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
target: 'ws://localhost:8000',
|
target: proxyTarget.replace(/^http/, 'ws'),
|
||||||
ws: true,
|
ws: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user