Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Commit

Permalink
Add react-native-dotenv npm package
Browse files Browse the repository at this point in the history
The project will use .env file to store build version and API_KEY

NOTE: typescript module for react-native-dotenv has to be created. Placed in src/config/env.d.ts
This module ensure Typescript that the environment variable in .env do exist and cause no issue

check zetachang/react-native-dotenv#76 (comment)
  • Loading branch information
Clumsy-Coder committed Apr 21, 2020
1 parent 77b8080 commit 6642d82
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ project-todo
android/release-keystore.properties
android/.bundle
android/vendor
.env
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
presets: ['module:metro-react-native-babel-preset', 'module:react-native-dotenv'],
plugins: [
[
'module-resolver',
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"native-base": "^2.13.12",
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-dotenv": "^0.2.0",
"react-redux": "^7.2.0",
"redux": "^4.0.5"
},
Expand All @@ -35,6 +36,7 @@
"@types/jest": "^25.2.1",
"@types/react": "^16.9.34",
"@types/react-native": "^0.62.2",
"@types/react-native-dotenv": "^0.2.0",
"@types/react-redux": "^7.1.7",
"@types/react-test-renderer": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^2.27.0",
Expand Down
6 changes: 6 additions & 0 deletions src/configs/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Create module to deal with Typescript error when pulling env values using react-native-dotenv
// check https://github.com/zetachang/react-native-dotenv/issues/76#issuecomment-585171009
declare module 'react-native-dotenv' {
export const BUILD_VERSION: 'development' | string;
export const API_KEY: string;
}
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,11 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==

"@types/react-native-dotenv@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@types/react-native-dotenv/-/react-native-dotenv-0.2.0.tgz#32c58422a422c1adf68acce363ed791314d5a8e7"
integrity sha512-ZxX+dU/yoQc0jTk+/NWttkiuXceJyN5FpOSqDl0WynN5GDzxwH7OMruQ47qcY8llo2RD3irjvzJ9BwC8gDiq0A==

"@types/react-native@^0.62.2":
version "0.62.2"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.62.2.tgz#f3e150f308c27089cefbcbfa3eb6cc14db279b2f"
Expand Down Expand Up @@ -2000,6 +2005,13 @@ babel-jest@^25.3.0:
chalk "^3.0.0"
slash "^3.0.0"

[email protected]:
version "0.1.1"
resolved "https://registry.yarnpkg.com/babel-plugin-dotenv/-/babel-plugin-dotenv-0.1.1.tgz#9c8faea67a7c034fe7e94099187ab2e7573400bc"
integrity sha1-nI+upnp8A0/n6UCZGHqy51c0ALw=
dependencies:
dotenv "^2.0.0"

babel-plugin-dynamic-import-node@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.0.tgz#f00f507bdaa3c3e3ff6e7e5e98d90a7acab96f7f"
Expand Down Expand Up @@ -2925,6 +2937,11 @@ domexception@^1.0.1:
dependencies:
webidl-conversions "^4.0.2"

dotenv@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-2.0.0.tgz#bd759c357aaa70365e01c96b7b0bec08a6e0d949"
integrity sha1-vXWcNXqqcDZeAclrewvsCKbg2Uk=

ecc-jsbn@~0.1.1:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9"
Expand Down Expand Up @@ -6665,6 +6682,13 @@ react-is@^16.12.0, react-is@^16.13.0, react-is@^16.7.0, react-is@^16.8.1, react-
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react-native-dotenv@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/react-native-dotenv/-/react-native-dotenv-0.2.0.tgz#311551cb6a35a3dcfede648bded55c0e3ece579d"
integrity sha1-MRVRy2o1o9z+3mSL3tVcDj7OV50=
dependencies:
babel-plugin-dotenv "0.1.1"

[email protected]:
version "2.5.1"
resolved "https://registry.yarnpkg.com/react-native-drawer/-/react-native-drawer-2.5.1.tgz#08b9314184f48c724f1b467f8859797369798654"
Expand Down

0 comments on commit 6642d82

Please sign in to comment.