[英]How to create new environments with create-react-app?
I am using react-scripts v2 (beta) and I have read the documentation here . 我正在使用react-scripts v2 (测试版),并且已经在此处阅读了文档。
We need to create many environments. 我们需要创建许多环境。
config/env
. config/env
文件夹下。 config/env/staging.js
because .env
seems to be only for root directory. config/env/staging.js
.env
使用javascript文件,因为.env
似乎仅用于根目录。 default
environment to be a default config under version control in config/env/default.js
, it must be the default configuration used when doing npm start
default
环境是config/env/default.js
版本控制下的默认配置,它必须是在执行npm start
时使用的默认配置。 config/env/default.local.js
config/env/default.local.js
Basically that can be reduced to two issues : 基本上可以简化为两个问题:
npm start/build
? npm start/build
上创建和选择新环境? without ejecting. 没有弹出。
Just copy the environment file to .env
before starting / building. 只需在开始/构建之前将环境文件复制到
.env
。 You can even put .env
in .gitignore
that way 您甚至可以将
.env
放在.gitignore
中
"start": "cp $ENV .env && react-scripts start"
Then run it: 然后运行它:
ENV=config/staging/.env npm start
There are lots of ways of doing what you want without ejecting, since it's all preprocessing (before your app starts / builds). 有很多方法可以完成您想做的事情而无需弹出,因为它们都是预处理(在您的应用启动/构建之前)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.