在RootConfig中的webpack.config.js中添加
devServer: {
proxy: {
'/api': {
target: 'http://localhost:7000',
pathRewrite: { '^/api': '' },
},
}
},
完整内容:
const { merge } = require("webpack-merge");
const singleSpaDefaults = require("webpack-config-single-spa");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = (webpackConfigEnv, argv) => {
const orgName = "Root";
const defaultConfig = singleSpaDefaults({
orgName,
projectName: "root-config",
webpackConfigEnv,
argv,
disableHtmlGeneration: true,
});
return merge(defaultConfig, {
// modify the webpack config however you'd like to by adding to this object
plugins: [
new HtmlWebpackPlugin({
inject: false,
template: "src/index.ejs",
templateParameters: {
isLocal: webpackConfigEnv && webpackConfigEnv.isLocal,
orgName,
},
}),
],
devServer: {
proxy: {
'/api': {
target: 'http://localhost:7000',
pathRewrite: { '^/api': '' },
},
}
},
});
};
附:webpack官网:https://webpack.docschina.org/configuration/dev-server/#devserverproxy