我在create-react-app中使用以下环境变量:
console.log(process.env.REACT_APP_API_URL) // http://localhost:5555
当我通过阅读npm run build
文件运行package.json
时,它可以工作:
REACT_APP_API_URL=http://localhost:5555
执行npm run build
时如何设置不同的值,例如package.json
?
这是我的package.json
文件:
{
"name": "webapp",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.9.0"
},
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
猜你喜欢: