React-native-config: Always use .env.dev file

Created on 31 Aug 2018  路  8Comments  路  Source: luggit/react-native-config

Environment:
react-native: 0.55.4
react-native-config: 0.11.5
cross-env: 5.2.0

Folder structure:
root
--app
--package.json
--env
--.env.dev
--.env.staging
--.env.production

NPM command:
"ios": "cross-env ENVFILE=env/.env.staging react-native run-ios --simulator='iphonex'"

Symptom:
Always use .env.dev config file even type npm command as above.

Someone can help me?

Thanks

Most helpful comment

Okay so after my long battle my conclusion is that java version may break this lib.
I had big problems with jdk 10, whereas on 8 I have none.

All 8 comments

try
"ios": "ENVFILE=.env.staging react-native run-ios --simulator='iPhoncex'"

Same here. In our case it always picks .env.prod, even when we don't set ENVFILE.
Our command is react-native run-ios.

Okay so after my long battle my conclusion is that java version may break this lib.
I had big problems with jdk 10, whereas on 8 I have none.

@piotrgrundas Looks like this is working for me, question is what are the disadvantages of downgrading from java 10 to java 8? Do you know any?

I did not notice any, to be honest.

Same here. It's work well on android. On iOS, I have to open Xcode, choose scheme and then build.

Hey guys.

I found how to select different .env file.

Root cause is that I set .env file in xcode scheme "Pre-actions".
React-native-config check if any .env file is set in build time.
If "YES", use xcode "Pre-actions" env file.

So, in my case, I set xcode scheme "Pre-actions" and I run npm command as below:

react-native run-ios --scheme test --simulator='XXX'

"test" is scheme name in xcode.
Now I can control which .env file I need!!!

I renamed my schemes on Xcode -> Product -> Scheme -> Manage Schemes like below:

Screen Shot 2019-09-17 at 09 58 32

After creating these three Schemes Development, Staging, Production.
I add to package.json these options to run project:

"scripts": {
    "run:ios:dev": "react-native run-ios --scheme Development",
    "run:ios:staging": "react-native run-ios --scheme Staging",
    "run:ios:prod": "react-native run-ios --scheme Production",
 }

This works fine. :)

Was this page helpful?
0 / 5 - 0 ratings