I have two different environments with named .env.demo
, .env.local
.
.env.demo
looks like this,
TEST_LABEL=Welcome to demo environment
.env.local
looks like this,
TEST_LABEL=Welcome to local environment
And here is my babel.config.js
,
module.exports = function (api) {
api.cache(true);
return {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
["module:react-native-dotenv",
{
"moduleName": "@env"
},]
]
};
};
this is the scripts in package.json
"scripts": {
"start": "react-native start",
"demo": "NODE_ENV=demo expo start",
"local": "NODE_ENV=local expo start",
"android": "react-native run-android",
"ios": "react-native run-ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest"
},
And this is how I used it in my Homescreen.js
import {TEST_LABEL} from "@env"
...
<Text>{TEST_LABEL}</Text>
And this displays always Welcome to local environment
even I run the demo env
I run the app like npm run demo
for demo environment, npm run local
for local environment.
I am using react-native-dotenv
from npm run demo doesn't pointing to demo
No comments:
Post a Comment