如何在生产环境中为 Webpack 设置代理
How to set up a proxy for Webpack in production
不知道为什么我不能 google 这个,但我似乎无法弄清楚如何在我创建的 webpack.config.prod.js 文件中代理我的 api 调用-反应应用程序。将它放在 package.json 文件中是行不通的,因为我在本地需要一个不同的代理。
我在 webpackDevServer.config.js 中设置了它,将它放在 module.exports
对象中效果很好。但是当我在 webpack.config.prod.js 中执行相同操作时它无法构建。如何针对产品进行设置?
proxy: {
'/myService/*': 'https://myServiceEndPoint/',
},
代理不适用于生产环境。
https://github.com/facebook/create-react-app/issues/1087#issuecomment-262611096
In production, CRA produces a static bundle. At this point you can do anything you want with it. The notion of a proxy doesn't make sense there because there is no development server. It is up to you to serve the bundle with any server, and you indeed can tweak the API call URLs depending on process.env.NODE_ENV or a custom environment variable
不知道为什么我不能 google 这个,但我似乎无法弄清楚如何在我创建的 webpack.config.prod.js 文件中代理我的 api 调用-反应应用程序。将它放在 package.json 文件中是行不通的,因为我在本地需要一个不同的代理。
我在 webpackDevServer.config.js 中设置了它,将它放在 module.exports
对象中效果很好。但是当我在 webpack.config.prod.js 中执行相同操作时它无法构建。如何针对产品进行设置?
proxy: {
'/myService/*': 'https://myServiceEndPoint/',
},
代理不适用于生产环境。
https://github.com/facebook/create-react-app/issues/1087#issuecomment-262611096
In production, CRA produces a static bundle. At this point you can do anything you want with it. The notion of a proxy doesn't make sense there because there is no development server. It is up to you to serve the bundle with any server, and you indeed can tweak the API call URLs depending on process.env.NODE_ENV or a custom environment variable