我需要为每个开发/生产服务器加载不同的.env文件。
Dev/Prod Server | .env file
---------------------------------------------
localhost | .env.development.local
development | .env.development
qa | .env.qa
production | .env.production
所以,我尝试以这种方式编辑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,因为NODE_ENV是生产环境。是否可能使用"build:*
命令加载其他.env文件?
build:qa
的脚本应该是什么?npm run build-css && react-scripts dotenv_config_path=qa.env
不识别dotenv_config_path
。 - Webman