Hi there,
Do the env values get bundled into the main.jsbundle? I'm thinking of using this in parallel with a service like CodePush, and just want to make sure I understand the expected behaviour when the js bundle is dynamically replaced. Will the env variables still be accessible in JS? Will the variables be from when the bundle was built, or from the app itself?
Hey!
Great question 鈥撀爐he configs are not bundled with js currently. They're defined in native land, where Gradle/Xcode can also read them.
It would be nice to have them defined in js too though, if anything because then we'd be able to reload the app to see config changes. CodePush support聽sounds great too, as long as developers understand that can't be used to change libraries setup natively (like the Facebook SDK, for instance).
I might take a stab at this at some point (aiming to use CodePush soon), but you're obviously welcome to give it a try too! Basically we'll have to generate a js file with the environment from .env, and use that to override what's returned from the native layer.
Just not sure if we can get the packager to generate a js file for us based off .env... would need to look into that.
Hey @pedro,
I think there is actually more value in keeping it all in native land. If we have config that we need defined in JS only, then there is nothing stopping you just using a JS file. From what you've said above it sounds like the env variables for a built app will be unchangeable, which could be helpful if for example you wanted to use the same JS app that behave differently depending upon an app configuration.
A good use case would be separate paid and free versions of the same app. You could have two builds that use the same JS file and simply detect from the .env whether all of the functionality should be available or not.
If we have config that we need defined in JS only, then there is nothing stopping you just using a JS file
Very true, but the idea here is exactly to have a single canonical way where all config is defined (.env) and accessed from (import Config from 'react-native-config', in JS land at least). I'd hate to see people writing config.js just so they can use it with CodePush, or to facilitate reloading under development. Thoughts?
Completely agree, if CodePush support could become a single source of truth (i.e. update native side and JS side). Not sure that that will be possible though? In which case, there would be two sources of truth, the JS bundle's truth and the native env's.
Right on! Yeah this could get confusing... Not sure how feasible it is either.
Well, I guess I'm closing this for now, but open to any further discussions/experimentations on this topic! Will update if I ever get to it too.
Thanks,
Hi,
I'm currently integrating with CodePush, and I was wondering if variables are still only kept in the native land?
Most helpful comment
Hey!
Great question 鈥撀爐he configs are not bundled with js currently. They're defined in native land, where Gradle/Xcode can also read them.
It would be nice to have them defined in js too though, if anything because then we'd be able to reload the app to see config changes. CodePush support聽sounds great too, as long as developers understand that can't be used to change libraries setup natively (like the Facebook SDK, for instance).
I might take a stab at this at some point (aiming to use CodePush soon), but you're obviously welcome to give it a try too! Basically we'll have to generate a js file with the environment from
.env, and use that to override what's returned from the native layer.Just not sure if we can get the packager to generate a js file for us based off
.env... would need to look into that.