Quickstart
September 2, 2021 · View on GitHub
This document covers basic setup assuming default react-native's template with single scheme/target on ios and default flavor on android.
For advanced setup please refer to cookbook
-
Add dependency
npm yarn npm install react-native-ultimate-configyarn add react-native-ultimate-config -
Create example file
echo "MY_CONFIG=hello" > .env -
Update .gitignore
Add this to
.gitignore:# react-native-ultimate-config rnuc.xcconfig -
ONLY FOR NPM. SKIP IF USING YARN
create script in "package.json"
"rnuc": "$(npm bin)/rnuc" -
Generate files
generate env files for native projects
npm yarn npm run rnuc .envyarn rnuc .env -
Configure native projects (one-off setup)
-
ios
- run
pod installin folderios - open workspace
- open Finder in folder
ios - drag'n'drop generated file into project

- go to project settings
- set
rnuc.configas root configuration for both "Debug" and "Release"

- run
-
-
apply plugin in gradle Add this right after applying react's plugin:
apply from: "../../node_modules/react-native-ultimate-config/android/rnuc.gradle"Final code:
apply from: "../../node_modules/react-native/react.gradle" apply from: "../../node_modules/react-native-ultimate-config/android/rnuc.gradle" -
expose
BuildConfigto the libraryin
MainApplication.javaadd// import module import com.reactnativeultimateconfig.UltimateConfigModule; ... @Override public void onCreate() { super.onCreate(); ... UltimateConfigModule.setBuildConfig(BuildConfig.class); // expose } -
If you are using ProGuard: in
proguard-rules.proadd the following snippet replacingMY_PACKAGEwith package identifier of yours, e.g.com.mypackage.BuildConfig.❗keep
<fields>as is. it SHALL NOT be replaced with actual field names-keepclassmembers class MY_PACKAGE.BuildConfig { public static <fields>; }
-
-
-
save changes made to native projects
.xcodeprojfile andbuild.gradle. DO NOT COMMMITrnuc.*files. -
Configure web projects (optional, one-off setup)
You can import your config into a web project as well (e.g. a project using React Native for Web).
react-native-ultimate-configvends a web-friendly CommonJS module using the package.json browser field. Most web bundlers support this with minimal effort:- Webpack - No configuration needed. If you choose to set target it must include
"web". - Rollup - Install @rollup/plugin-node-resolve and set
browsertotrue. - Parcel - No configuration needed.
- Browserify - No configuration needed.
- Webpack - No configuration needed. If you choose to set target it must include
-
from now on every time you need to switch environment just run
npm run rnuc <dotenv file>oryarn rnuc <dotenv file>and rerun your native project (withreact-native run-{ios,android}) or web project (with your web bundler of choice)