# 默认测试环境 .env
REACT_APP_ENV=development
# 预发布环境 .env.test
REACT_APP_ENV=prepare
# 线上环境 .env.production
REACT_APP_ENV=production
注:必须是以REACT_APP开头的变量 才可以。
"scripts": {
"start": "react-scripts start",
"start:pre": "dotenv -e .env.test react-scripts start",
"start:pro": "dotenv -e .env.production react-scripts start",
"build": "react-scripts build",
"build:pre": "dotenv -e .env.test react-scripts build",
"build:pro": "dotenv -e .env.production react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
const mode = process.env.REACT_APP_ENV ;
console.log('mode',mode)