Browse Source

配置开发环境,使用调试服务器作为代理,避免浏览器的CORS问题;设置启动时使用localhost作为域名,不使用固定本机IP,兼容多种开发环境

dengdx 2 months ago
parent
commit
87b71d5a68
1 changed files with 14 additions and 1 deletions
  1. 14 1
      config/dev.ts

+ 14 - 1
config/dev.ts

@@ -6,5 +6,18 @@ export default {
     stats: true,
     stats: true,
   },
   },
   mini: {},
   mini: {},
-  h5: {},
+  h5: {
+    devServer: {
+      proxy: {
+        '/dr': {
+          target: 'http://192.168.11.4:6001', // 你的后端服务地址
+          changeOrigin: true, // 允许跨域
+          // pathRewrite: {
+          //   '^/dr/api': '' // 可选,用于重写路径
+          // }
+        },
+      },
+      host: 'localhost', // 这里设置你想要的主机名,
+    },
+  },
 } satisfies UserConfigExport<'webpack5'>;
 } satisfies UserConfigExport<'webpack5'>;