瀏覽代碼

4. 完善系统配置

mcbaiyun 6 月之前
父節點
當前提交
45cf850b8f
共有 1 個文件被更改,包括 26 次插入13 次删除
  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/, ""),
+        },
+      },
+    },
+  };
+});