react-native-config
Advanced tools
Comparing version
{ | ||
"name": "react-native-config", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Expose config variables to React Native apps", | ||
@@ -5,0 +5,0 @@ "keywords": ["env", "config", "config-var", "react-native", "android", "ios", "12factor"], |
@@ -14,3 +14,3 @@ # Config variables for React Native apps | ||
API_URL=https://myapi.com | ||
LOG_ERRORS=true | ||
GOOGLE_MAPS_API_KEY=abcdefgh | ||
``` | ||
@@ -23,7 +23,56 @@ | ||
Config.API_URL // 'https://myapi.com' | ||
Config.SHOW_ERRORS // 'true' | ||
Config.API_URL // 'https://myapi.com' | ||
Config.GOOGLE_MAPS_API_KEY // 'abcdefgh' | ||
``` | ||
### Android | ||
Config variables set in `.env` are available to your Java classes via `BuildConfig`: | ||
```java | ||
public HttpURLConnection getApiClient() { | ||
URL url = new URL(BuildConfig.API_URL); | ||
// ... | ||
} | ||
``` | ||
You can also read them from your Gradle configuration: | ||
```groovy | ||
signingConfigs { | ||
release { | ||
storeFile file(project.env.get("RELEASE_STORE_FILE")) | ||
storePassword project.env.get("RELEASE_STORE_PASSWORD") | ||
keyAlias project.env.get("RELEASE_KEY_ALIAS") | ||
keyPassword project.env.get("RELEASE_KEY_PASSWORD") | ||
} | ||
} | ||
``` | ||
And use them to configure libraries in `AndroidManifest.xml` and others: | ||
```xml | ||
<meta-data | ||
android:name="com.google.android.geo.API_KEY" | ||
android:value="@string/GOOGLE_MAPS_API_KEY" /> | ||
``` | ||
### iOS | ||
Xcode support is missing; variables declared in `.env`. can be consumed from React Native apps in iOS via `Config`, but not from `plist` files. | ||
### Different environments | ||
Save config for different environments in different files: `.env.staging`, `.env.production`, etc. | ||
By default react-native-config will read from `.env`, but you can change it setting `ENVFILE` before running it, like: | ||
``` | ||
$ ENVFILE=.env.staging react-native run-android | ||
``` | ||
This is only support in Android at the moment – The iOS equivalent should be coming soon. | ||
## Setup | ||
@@ -30,0 +79,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
51421
6.77%21
10.53%137
55.68%