How to manage multiple configuration


#1

I saw this How do I manage different environments, eg: staging and production? but that seems to be for app.json

For me, I am looking for information about how to setup the environment with multiple configurations. For example, the API endpoint for my development and testing is not the same for production so how could I approach this?

I could require some file but still I need some soft of environment to be able to switch configurations


#2

you can use app.json along with the extra field: https://docs.expo.io/versions/latest/guides/configuration.html#extra


#3

But app.json is a sigle file, that means that I have to add it to the git ignore and keep chaning the configs based on the environment right?

There is not other clean way to do this? Doesn’t the environment pass some flag that I could inside?


#4

@notbrent wouldn’t be better to just add some file to the git ignore like config.js and Javascript dont care about it as long as it’s there.

What do you think? Unless the Expo do not upload or do something like that the ignored files


#5

expo does not do anything about your gitignore, if you require the file then it is used. sure, you can do that, whatever works for you!

to determine the environment you could do:

  • Constants.manifest.xde - this is true when in development (in either xde or exp).
  • __DEV__ if this is true, development mode is enabled (you can disable development mode while working in xde)
  • Constants.manifest.releaseId - this is a string when deployed, __DEV__ is false here

we will add first-class support for environments at some point but right now you’ll need to do something like what was suggested in the original thread you linked to or the above.


#6

Is there a way to disable __DEV__ using exp?


#7

Hey @philip_mvpfastlane, check out exp documentation here: https://docs.expo.io/versions/latest/guides/exp-cli.html

On exp start you can add flag --no-dev.


#8

Are you sure extra is working? I’m on “22.0.0” and added “extra”: { “foo”: “bar” } to app.json. I get undefined when calling Expo.Constants.manifest.extra (not in the Expo.Constants.manifest object).


#9

I’m not sure if you’ve tried this but when making changes to app.json you should restart XDE/exp and also force quit the client app for good measure (the latter is technically not necessary but the more state we can clear the better).


#10

Yup, restarting XDE worked.