I use babel-plugin-transform-inline-environment-variables
.
What I did was put a configuration files within S3 with my different environments.
s3://example-bucket/dev-env.sh
s3://example-bucket/prod-env.sh
s3://example-bucket/stage-env.sh
EACH env file:
FIRSTENV=FIRSTVALUE
SECONDENV=SECONDVALUE
Afterwards, I added a new script in my package.json
that runs a script for bundling
if [ "$ENV" == "production" ]
then
eval $(aws s3 cp s3://example-bucket/prod-env.sh - | sed 's/^/export /')
elif [ "$ENV" == "staging" ]
then
eval $(aws s3 cp s3://example-bucket/stage-env.sh - | sed 's/^/export /')
else
eval $(aws s3 cp s3://example-bucket/development-env.sh - | sed 's/^/export /')
fi
react-native start
Within your app you will probably have a config file that has:
const FIRSTENV = process.env['FIRSTENV']
const SECONDENV = process.env['SECONDENV']
which will be replaced by babel to:
const FIRSTENV = 'FIRSTVALUE'
const SECONDENV = 'SECONDVALUE'
REMEMBER you have to use process.env['STRING']
NOT process.env.STRING
or it won't convert properly.