如何使用 create-react-app 创建新环境?

How to create new environments with create-react-app?

我正在使用 react-scripts v2 (beta) and I have read the documentation here

我们需要创造很多环境。

基本上可以归结为两个问题:

  1. 是否可以重新定位 env 位置文件夹?
  2. 我们如何在 npm start/build 上创建和 select 新环境?

不弹出。

在开始/构建之前将环境文件复制到.env。你甚至可以把 .env 放在 .gitignore

"start": "cp $ENV .env && react-scripts start"

然后运行它:

ENV=config/staging/.env npm start

有很多方法可以在不弹出的情况下做你想做的事,因为这都是预处理(在你的应用程序启动/构建之前)。