React-native-config: Run iOS app without `react-native run-ios`

Created on 10 Mar 2018  路  4Comments  路  Source: luggit/react-native-config

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!

Most helpful comment

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.

All 4 comments

@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 /config/.env.dev and I am adding a pre action which is
echo "config/.env.prod" > /tmp/envfile

But no success. Please help

Was this page helpful?
0 / 5 - 0 ratings