Reactjs 使用.env加载不同的env变量并创建react app

Reactjs 使用.env加载不同的env变量并创建react app,reactjs,environment-variables,create-react-app,Reactjs,Environment Variables,Create React App,我需要为每个开发/生产服务器加载一个不同的.env文件 Dev/Prod Server | .env file --------------------------------------------- localhost | .env.development.local development | .env.development qa | .env.qa production | .env.pro

我需要为每个开发/生产服务器加载一个不同的.env文件

Dev/Prod Server     | .env file
---------------------------------------------
localhost           | .env.development.local
development         | .env.development
qa                  | .env.qa
production          | .env.production
Dev/Prod Server     | .env file
---------------------------------------------
qa                  | qa.env
因此,我尝试以这种方式编辑package.json

"start-js": "react-scripts start .env.development.local",
"start": " npm-run-all -p watch-css start-js",
"build:dev": "npm run build-css && react-scripts build .env.development",
"build:qa": "npm run build-css && react-scripts build .env.qa",
"build:pro": "npm run build-css && react-scripts build .env.production"

但是如果执行
build:
命令,则加载的文件始终是.env.production,因为节点_env是production。是否可以使用
“build:
命令加载其他.env文件?

我使用react app env并重命名.env文件解决了我的问题

Dev/Prod Server     | .env file
---------------------------------------------
localhost           | .env.development.local
development         | .env.development
qa                  | .env.qa
production          | .env.production
Dev/Prod Server     | .env file
---------------------------------------------
qa                  | qa.env
例如,
build:qa
脚本变成:

"build": "npm run build-css && react-scripts build",
"build:qa": "react-app-env --env-file=qa.env build"
我是的作者。它是一个命令行工具,用于从Keepass条目(Notes字段中的内容)快速切换.env文件

只需运行
env development
即可替换
.env
文件

运行
纱线切换器env production
并用生产文件替换
.env
文件


基本上,您的所有.env文件都作为条目存储在Keepass文件中。每个条目的.env文件内容都应存储在备注字段中。使用
switchenv
读取该Keepass文件,并用该条目的备注替换
.env
文件。

尝试查看dotenv。您可以使用it@ReiDien使用dotenv的
build:qa
脚本应该是什么?
npm运行构建css和反应脚本dotenv\u config\u path=qa.env
不识别
dotenv\u config\u path