React-Native의 자바스크립트 코드에서 환경변수를 구성할 때  react-native-config를 사용한다.

react-native-config 모듈은 패키징을 할 때 데이터를 난독화 하거나 암호화 하지 않음으로 민감한 정보에 대해서는 값을 넣지 않는 것을 추천한다.

 

https://github.com/luggit/react-native-config

 

GitHub - luggit/react-native-config: Bring some 12 factor love to your mobile apps!

Bring some 12 factor love to your mobile apps! Contribute to luggit/react-native-config development by creating an account on GitHub.

github.com

- 사용밥법

 

react-native-config npm 모듈 설치

npm install react-native-config

 

프로젝트 root에 .env파일을 생성하고 아래와 같이 환경변수 값을 설정하여 사용한다.(key=value)

API_URL=https://apiurl

 

사용하고자 하는 자바스크립스 소스에 import

import Config from 'react-native-config';

import 후에 아래와 같은 형식으로 사용하면 된다.

const url = Config.API_URL;
  • Android

android/app/proguard-rules.pro 에 아래내용 추가

-keep class com.fooddeliveryapp.BuildConfig { *; }

android/app/build.gradle에 아래내용 추가

apply plugin: "com.android.application"

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

...

    defaultConfig {

        ...

        resValue "string", "build_config_package", "com.fooddeliveryapp"

    }
  • IOS

ios/podfile에 아래 내용추가

pod 'react-native-config', :path => '../node_modules/react-native-config/react-native-config.podspec'

pod install 실행 (프로젝트/ios 경로에서)

pod install

 

로컬서버와 테스트 시 일반적으로 localhost 또는 127.0.0.1로 테스트를 진행하지만, 안드로이드 에뮬레이터와 테스트 시에는 10.0.2.2 로 설정을 해야한다.

 

안드로이드 에뮬레이터 네트워킹 설정참고

https://developer.android.com/studio/run/emulator-networking?hl=ko

사이드 바 열고/닫기
Windows Ctrl + B
MacOS : Cmd + B


빠른 열기(파일이나 기호 탐색)
Windows Ctrl + P
MacOS : Cmd + P


모든 명령 표시 (에디터의 모든 명령에 접근)
Windows Ctrl + Shift + P
MacOS : Cmd + Shift + P


편집 닫기
Windows Ctrl + W
MacOS : Cmd + W

찾기 탐색
Windows Ctrl + F
MacOS : Cmd + F


찾기(검색)/바꾸기(대체)
Windows Ctrl + H
MacOS : Cmd + Alt(Opt)+ F 

줄 위로 이동할수
Windows Alt(Opt) + Up
MacOS : Alt + Up

줄 아래로 이동할수
Windows Alt(Opt) + Down
MacOS : Alt + Down

아래 줄 복사
Windows Alt(Opt) + Shift + Down
MacOS : Alt + Shift + Down

위에 줄 복사
Windows Alt(Opt) + Shift + UP
MacOS : Alt + Shift + UP

들여쓰기
MacOS : Tab
Widows : Tab

+ Recent posts