【发布时间】:2018-01-09 19:57:15
【问题描述】:
我正在开发一个 React Web 应用程序,我正在使用 create-react-app npm 实用程序。
我的应用程序与在开发过程中位于我的本地计算机上的服务器通信。出于这个原因,我发出的所有 Ajax 请求都使用localhost:port 地址。
当然,当我要在生产环境中构建和部署我的项目时,我需要将这些地址更改为生产环境。
我习惯了 preprocess Grunt 插件流程 (https://github.com/jsoverson/grunt-preprocess),它可以在构建时标记要排除、包含或更改的部分代码。
例如:
//@if DEV
const SERVER_PATH = "localhost:8888";
//@endif
//@if !DEV
const SERVER_PATH = "prot://example.com:8888";
//@endif
您知道在create-react-app 开发环境中是否有办法做到这一点?
提前谢谢你!
【问题讨论】:
标签: javascript reactjs build preprocessor create-react-app