我正在使用create react app引导我的应用程序。
我已经添加了两个.env文件.env.development,并.env.production在根。
我的.env.development包括:
API_URL=http://localhost:3000/api
CALLBACK_URL=http://localhost:3005/callback
当我使用来运行我的应用程序react-scripts start并退出时,process.env它会吐出来
{ NODE_ENV: "development", PUBLIC_URL: "" }
我尝试了不同的方法,但只是没有在开发文件中使用Veriable,我在做什么错?!
指令结构为:
/.env.development
/src/index.js
Package.json脚本是:
"start": "export PORT=3005; npm-run-all --parallel server:start client:start",
"client:start": "export PORT=3005; react-scripts start",
"server:start": "node server.js",
"build": "react-scripts build",
编辑:
@jamcreencia正确地指出我的变量应该前缀用REACT_APP。
编辑2
如果我为文件命名,则可以,.env但是如果我使用.env.development或.end.production
package.json文件吗?