From a1a3fa45b1ee91eeee8f1fead33350b47b692aaf Mon Sep 17 00:00:00 2001 From: Kat Huang Date: Fri, 5 Jan 2024 19:50:07 -0700 Subject: [PATCH] Use environment variables for uri --- .env.development | 2 ++ .env.production | 2 ++ babel.config.js | 9 +++++++++ package.json | 7 +++++-- yarn.lock | 12 ++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 .env.development create mode 100644 .env.production diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..690bd0d --- /dev/null +++ b/.env.development @@ -0,0 +1,2 @@ +# .env.development +API_URI=https://api-dev.example.com/graphql diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..bd93d70 --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +# .env.production +API_URI=https://api.example.com/graphql diff --git a/babel.config.js b/babel.config.js index 8ce5260..46e0f89 100644 --- a/babel.config.js +++ b/babel.config.js @@ -2,5 +2,14 @@ module.exports = function(api) { api.cache(true); return { presets: ["babel-preset-expo"], + plugins: [ + ["module:react-native-dotenv", { + "moduleName": "@env", + "path": ".env", + "safe": false, + "allowUndefined": true, + "verbose": false, + }], + ], }; }; diff --git a/package.json b/package.json index ada3013..0042feb 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "dummyapp", + "name": "railbird-rn", "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { @@ -8,7 +8,9 @@ "ios": "expo start --ios", "web": "expo start --web", "lint": "eslint . --ext .js,.ts,.tsx", - "lint:fix": "eslint . --ext .ts,.tsx --fix" + "lint:fix": "eslint . --ext .ts,.tsx --fix", + "start:dev": "ENVFILE=.env.development react-native start", + "start:prod": "ENVFILE=.env.production react-native start" }, "dependencies": { "@types/react": "~18.2.14", @@ -22,6 +24,7 @@ "expo-status-bar": "~1.6.0", "react": "18.2.0", "react-native": "0.72.6", + "react-native-dotenv": "^3.4.9", "typescript": "^5.3.3" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 8d163cd..39d882b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3270,6 +3270,11 @@ dotenv-expand@~10.0.0: resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37" integrity sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A== +dotenv@^16.3.1: + version "16.3.1" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" + integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== + dotenv@~16.0.3: version "16.0.3" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07" @@ -6288,6 +6293,13 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== +react-native-dotenv@^3.4.9: + version "3.4.9" + resolved "https://registry.yarnpkg.com/react-native-dotenv/-/react-native-dotenv-3.4.9.tgz#621c5b0c1d0c5c7f569bfe5a1d804bec7885c010" + integrity sha512-dbyd+mcy7SUzxEgmt33TRf1FGcNe6swJhXmB0unKkI49F7+pidog9kPtjxMLTAfmKA8gcN2XHQSKltGfGbGCLQ== + dependencies: + dotenv "^16.3.1" + react-native@0.72.6: version "0.72.6" resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.72.6.tgz#9f8d090694907e2f83af22e115cc0e4a3d5fa626"