Bring some 12 factor love to your mobile apps!
Go to file
Pedro Belo 7c3066633d v0.0.2 2016-02-23 17:32:30 -08:00
Example fix dotenv in ios 2016-02-23 15:50:03 -08:00
android save env in project.env with gradle so it can be reused 2016-02-23 16:25:35 -08:00
ios fix dotenv in ios 2016-02-23 15:50:03 -08:00
.gitignore gitignore 2016-02-22 17:21:49 -08:00
README.md sweet, rnpm is working 2016-02-23 16:42:53 -08:00
index.android.js bring android implementation from react-native-android-config 2016-02-22 13:24:36 -08:00
index.ios.js setup example app to consume ios stub 2016-02-22 17:37:50 -08:00
package.json v0.0.2 2016-02-23 17:32:30 -08:00

README.md

Config variables for React Native apps

Module to expose config variables to your javascript code in React Native, supporting both iOS and Android.

Bring some 12 factor love to your mobile apps!

Usage

Declare config variables in .env:

API_URL=https://myapi.com
LOG_ERRORS=true

Then access from your app:

import Config from 'react-native-config'

Config.API_URL     // 'https://myapi.com'
Config.SHOW_ERRORS // 'true'

Setup

Install the package:

$ npm install react-native-config --save

Then follow the platform-specific instructions below:

iOS

Link the library with rnpm:

$ rnpm link react-native-config

Android

Include this module in android/settings.gradle:

include ':react-native-config'
include ':app'

project(':react-native-config').projectDir = new File(rootProject.projectDir,
  '../node_modules/react-native-config/android')

Apply a plugin and add dependency to your app build, in android/app/build.gradle:

// 2nd line, add a new apply:
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

// down below, add new compile:
dependencies {
    ...
    compile project(':react-native-android-config')
}

Change your main activity to add a new package, in android/app/src/main/.../MainActivity.java:

import com.lugg.ReactNativeConfig.ReactNativeConfigPackage; // add import

public class MainActivity extends ReactActivity {
    // ...

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new ReactNativeConfigPackage() // add package
        );
    }