记录一下

module.exports = {
  publicPath: '/myProject',
  devServer: {
    disableHostCheck: true, //webpack4.0 开启热更新
    proxy: {
      '/localApi': {
        target: 'http://ip:port/api/',
        changeOrigin: true,
        pathRewrite: { '/myProject/localApi': '' },
      },
    },
  },
};

需要在pathRewrite里加上publicPath的名称,不然代理的地址会多出来它

vue3+vite的(vite.config.ts)

// https://vitejs.dev/config/
export default defineConfig({
  base: "/myProject/",
  plugins: [vue()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    proxy: {
      "/myProject/localApi": {
        target: "http://localApi/api/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/myProject\/localApi/, ""),
      },
    },
  },
});

Logo

前往低代码交流专区

更多推荐