在package.json中,修改
"build": "react-app-rewired build --max-old-space-size=2048",
"build:test": "set REACT_APP_ENV=test && react-app-rewired build --max-old-space-size=2048",
"build:pro": "set REACT_APP_ENV=pro && react-app-rewired build --max-old-space-size=2048",

项目中其他js文件的使用
const REACT_APP_ENV = process.env.REACT_APP_ENV
let targetUrl = ''
if (REACT_APP_ENV === 'test') {
targetUrl= 'http://aaa:3000';
}else if(REACT_APP_ENV === 'pro'){
targetUrl= 'http://bbb:3000';
}else {
targetUrl= 'http://ccc:3000';
}

网友评论