Skip to content
Kemal Ahmed edited this page Jan 20, 2021 · 64 revisions

Welcome to the react-native-dotenv wiki!

Docs TODOs

  • make sure to add metro
module.exports = {
  "presets": ["module:metro-react-native-babel-preset"],
  "plugins": [
    ["module:react-native-dotenv"]
  ]
}
  • release vs debug
react-native run-ios --configuration Release
  • Variables caching (add to caveats)

yarn start --reset-cache

expo r -c

Maybe a solution for updating package.json scripts:

"cc": "rimraf node_modules/.cache/babel-loader/*,",
"android": "npm run cc && react-native run-android",
"ios": "npm run cc && react-native run-ios",

Typescript

  • Create a types folder in your project
  • Inside that folder, create a *.d.tsfile, say, env.d.ts
  • in that file, declare a module as the following format:
declare module '@env' {
  export const API_BASE: string;
}

You should add all of your .env variables inside this module.

  • Finally, add this folder into the typeRoots field in your tsconfig.json file:
{
...
    "typeRoots": ["./src/types"],
...
}

Publishing

Version bump

Clone this wiki locally