Thanks for this awesome library!
Is it possible to change .env files based on environment variables set in my package.json but run my app by opening Xcode and pressing "play".
It's not currently working because I'm guessing my shell window and xcode don't share an environment, so is there any way for me to run ENVFILE=.env.staging npm start followed by opening Xcode and pressing play?
Thanks for any help!
@jemise111 Have you added the pre-action in the build step?
Product > Scheme > Edit Scheme > Build > Pre-actions
Hit the plus and add a script
if [ "${ENVFILE}" ]; then echo "${ENVFILE}" > /tmp/envfile ; else echo ".env.staging" > /tmp/envfile; fi
The only thing that has worked for me when building through xcode is to overwrite the .env file with the desired environment file. In other words: cp .env.staging .env.
Try adding this in the scripts of package.json
"ios:stage": "ENVFILE=.env.stage react-native run-ios --scheme YOUR_STAGE_SCHEME_NAME"
Then simply run npm run ios:stage from terminal.
My env file is in config folder. Its like
echo "config/.env.prod" > /tmp/envfile
But no success. Please help
Most helpful comment
Try adding this in the
scriptsofpackage.json"ios:stage": "ENVFILE=.env.stage react-native run-ios --scheme YOUR_STAGE_SCHEME_NAME"Then simply run
npm run ios:stagefrom terminal.