简体   繁体   English

如何在 React 项目的构建中更改 api 地址?

[英]How do I change the api addresses in the build of the React project?

In my React project, I want to change the api addresses after build it.在我的 React 项目中,我想在构建后更改 api 地址。 I want to be able to change their address dynamically.我希望能够动态更改他们的地址。 is There a way I can do this?有没有办法我可以做到这一点? I do not want to use the environment.我不想使用环境。 Because when I get build, I can not change api address因为当我构建时,我无法更改 api 地址

Use the NODE_ENV env variable to check the environment使用 NODE_ENV 环境变量检查环境

if (process.env.NODE_ENV === 'production') {
  // Set the API URL for prod
}

Set NODE_ENV=production when running your build script运行构建脚本时设置NODE_ENV=production

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 npm 上发布之前,我是否必须构建 React Javascript 项目? - Do I have to build the React Javascript project before publishing on npm? 如何在 React 项目中更改生产版本 static 文件夹路径? - How to change production build static folder path in a React project? 如何从 React Native 项目中从 WordPress API 端点获取的数据中删除 HTML 字符? - How do I remove HTML characters from the data fetched from a WordPress API endpoint in a React Native project? 如何限制 Google Maps API 结果以防止返回对不存在的地址的估计 - How do I limit Google Maps API results to prevent returning estimate on addresses that do not exist Mapbox API:如何获取给定邮政编码下的地址列表? - Mapbox API: How do I get a list of addresses under a given postal code? 如何将具有可变URL地址的JSON API超链接返回值? - How do I hyperlink JSON API return values with variable URL addresses? 如何使用 HTML5 地理定位或 Google API 获取地址经纬度? - How do I get an addresses latitude-longitude using HTML5 geolocation or Google API? 如何在 build 文件夹中构建 react 项目 - How build a react project inside build folder 如何在 React 中正确更改 2 个状态? - How do I change 2 states properly in React? 如何在 React 中动态调用 API? - How do I dynamically call API in React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM