lrf 2 years ago
parent
commit
7807c08b4a
5 changed files with 32 additions and 16 deletions
  1. 2 0
      .env.development
  2. 2 0
      .env.production
  3. 1 0
      .gitignore
  4. 4 0
      env.d.ts
  5. 23 16
      vite.config.ts

+ 2 - 0
.env.development

@@ -0,0 +1,2 @@
+VITE_BASE_URL = "/dbInit"
+VITE_OUT_DIR = "dbInit"

+ 2 - 0
.env.production

@@ -0,0 +1,2 @@
+VITE_BASE_URL = "/dbInit"
+VITE_OUT_DIR = "dbInit"

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
+/dbInit
 # Logs
 logs
 *.log

+ 4 - 0
env.d.ts

@@ -1 +1,5 @@
 /// <reference types="vite/client" />
+interface ImportMetaEnv {
+  VITE_BASE_URL: string;
+  VITE_OUT_DIR: string;
+}

+ 23 - 16
vite.config.ts

@@ -1,25 +1,32 @@
 import { fileURLToPath, URL } from 'node:url';
 
-import { defineConfig } from 'vite';
+import { defineConfig, loadEnv } from 'vite';
 import vue from '@vitejs/plugin-vue';
 
 // https://vitejs.dev/config/
-export default defineConfig({
-  plugins: [vue()],
-  server: {
-    port: 20001,
-    proxy: {
-      '/api/live/v0': {
-        target: 'http://broadcast.waityou24.cn',
-      },
-      '/api/util/dbInit': {
-        target: 'http://broadcast.waityou24.cn',
+export default defineConfig(({ mode }) => {
+  const env = loadEnv(mode, __dirname);
+  return {
+    base: env.VITE_BASE_URL,
+    build: {
+      outDir: env.VITE_OUT_DIR,
+    },
+    plugins: [vue()],
+    server: {
+      port: 20001,
+      proxy: {
+        '/api/live/v0': {
+          target: 'http://broadcast.waityou24.cn',
+        },
+        '/api/util/dbInit': {
+          target: 'http://broadcast.waityou24.cn',
+        },
       },
     },
-  },
-  resolve: {
-    alias: {
-      '@': fileURLToPath(new URL('./src', import.meta.url)),
+    resolve: {
+      alias: {
+        '@': fileURLToPath(new URL('./src', import.meta.url)),
+      },
     },
-  },
+  };
 });