最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set up a proxy for Webpack in production - Stack Overflow

programmeradmin6浏览0评论

No idea why I can't google this, but I can't seem to figure out how to proxy my api calls in the webpack.config.prod.js file of my create-react-app. Putting it in the package.json file won't do because I need a different proxy locally.

I have it set up in the webpackDevServer.config.js, works great by putting it in the module.exports object. But it fails to build when I do the same in the webpack.config.prod.js. How to set this up for prod?

proxy: {
  '/myService/*': 'https://myServiceEndPoint/',
},

No idea why I can't google this, but I can't seem to figure out how to proxy my api calls in the webpack.config.prod.js file of my create-react-app. Putting it in the package.json file won't do because I need a different proxy locally.

I have it set up in the webpackDevServer.config.js, works great by putting it in the module.exports object. But it fails to build when I do the same in the webpack.config.prod.js. How to set this up for prod?

proxy: {
  '/myService/*': 'https://myServiceEndPoint/',
},
Share Improve this question asked Sep 19, 2018 at 19:09 jmargolisvtjmargolisvt 6,0985 gold badges31 silver badges49 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Proxy is not meant to be used in production environment.

https://github./facebook/create-react-app/issues/1087#issuement-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

发布评论

评论列表(0)

  1. 暂无评论