Parcourir la source

4. 完善系统配置

mcbaiyun il y a 6 mois
Parent
commit
45cf850b8f
1 fichiers modifiés avec 26 ajouts et 13 suppressions
  1. 26 13
      vite.config.js

+ 26 - 13
vite.config.js

@@ -1,14 +1,27 @@
-import { fileURLToPath, URL } from 'node:url'
-
-import { defineConfig } from 'vite'
-import vue from '@vitejs/plugin-vue'
-
+import { fileURLToPath, URL } from "node:url";
+import { defineConfig, loadEnv } from "vite";
+import vue from "@vitejs/plugin-vue";
 // https://vitejs.dev/config/
-export default defineConfig({
-  plugins: [vue()],
-  resolve: {
-    alias: {
-      '@': fileURLToPath(new URL('./src', import.meta.url))
-    }
-  }
-})
+export default defineConfig(({ mode }) => {
+  const env = loadEnv(mode, process.cwd());
+  console.log(env);
+  // const { VUE_APP_BASE_API } = env
+  return {
+    plugins: [vue()],
+    resolve: {
+      alias: {
+        "@": fileURLToPath(new URL("./src", import.meta.url)),
+      },
+    },
+    server: {
+      port: 3000,
+      proxy: {
+        "/api/": {
+          target: env.VITE_APP_SERVER_URL,
+          changeOrigin: true,
+          rewrite: (path) => path.replace(/^\/api/, ""),
+        },
+      },
+    },
+  };
+});