Vue2/3 config里配置publicPath/base之后proxy的配置修改
记录一下module.exports = {publicPath: '/myProject',devServer: {disableHostCheck: true, //webpack4.0 开启热更新proxy: {'/localApi': {target: 'http://ip:port/api/',changeOrigin: true,pathRewrite: { '/myProject/l
·
记录一下
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/, ""),
},
},
},
});
更多推荐
已为社区贡献3条内容
所有评论(0)