All Projects → zetachang → React Native Dotenv

zetachang / React Native Dotenv

Licence: mit
A Babel preset let you import application configs from .env file (zero runtime dependency)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Native Dotenv

Express Mongoose Es6 Rest Api
💥 A boilerplate application for building RESTful APIs Microservice in Node.js using express and mongoose in ES6 with code coverage and JsonWebToken Authentication
Stars: ✭ 2,811 (+214.08%)
Mutual labels:  babel, dotenv
Reactjs Tmdb App
Responsive React 'The Movie Database' (TMDb) App
Stars: ✭ 830 (-7.26%)
Mutual labels:  babel
Presspack
💻 Wordpress like it's 2020 with Webpack and Docker
Stars: ✭ 658 (-26.48%)
Mutual labels:  babel
Awesome Babel
😎A list of awesome Babel plugins, presets, etc.
Stars: ✭ 770 (-13.97%)
Mutual labels:  babel
React Ssr Setup
React Starter Project with Webpack 4, Babel 7, TypeScript, CSS Modules, Server Side Rendering, i18n and some more niceties
Stars: ✭ 678 (-24.25%)
Mutual labels:  babel
React Things
Коллекция материалов для изучения React
Stars: ✭ 789 (-11.84%)
Mutual labels:  babel
Serverless Typescript Starter
🗄🙅‍♀️ Deploy your next serverless JavaScript function in seconds
Stars: ✭ 653 (-27.04%)
Mutual labels:  babel
Generator Node Module
A Yeoman module to author Node libraries with Prettier, Jest, Flow and Babel.
Stars: ✭ 16 (-98.21%)
Mutual labels:  babel
Htm
Hyperscript Tagged Markup: JSX alternative using standard tagged templates, with compiler support.
Stars: ✭ 7,299 (+715.53%)
Mutual labels:  babel
Generator Angular Fullstack
Yeoman generator for an Angular app with an Express server
Stars: ✭ 6,135 (+585.47%)
Mutual labels:  babel
React Article Bucket
总结,积累,分享,传播JavaScript各模块核心知识点文章全集,欢迎star,issue(勿fork,内容可能随时修改)。webpack核心内容部分请查看专栏: https://github.com/liangklfangl/webpack-core-usage
Stars: ✭ 750 (-16.2%)
Mutual labels:  babel
Nylas Mail
💌 An extensible desktop mail app built on the modern web. Forks welcome!
Stars: ✭ 24,653 (+2654.53%)
Mutual labels:  babel
Babel Standalone
🎮 Now located in the Babel repo! Standalone build of Babel for use in non-Node.js environments, including browsers.
Stars: ✭ 806 (-9.94%)
Mutual labels:  babel
Sagui
🐒 Front-end tooling in a single dependency
Stars: ✭ 676 (-24.47%)
Mutual labels:  babel
Svelte Quickstart
Svelte un nuevo framework de JavaScript para construir interfaces de usuario.
Stars: ✭ 16 (-98.21%)
Mutual labels:  babel
React Isomorphic Boilerplate
🌟 An universal React isomorphic boilerplate for building server-side render web app.
Stars: ✭ 653 (-27.04%)
Mutual labels:  babel
Preset Modules
A Babel preset that targets modern browsers by fixing engine bugs (will be merged into preset-env eventually)
Stars: ✭ 730 (-18.44%)
Mutual labels:  babel
Minimal React Webpack Babel Setup
The minimal React, Webpack, Babel Setup. You want to get beyond create-react-app?
Stars: ✭ 777 (-13.18%)
Mutual labels:  babel
Braid Design System
Themeable design system for the SEEK Group
Stars: ✭ 888 (-0.78%)
Mutual labels:  babel
Babel Plugin Transform React Remove Prop Types
Remove unnecessary React propTypes from the production build. 🎈
Stars: ✭ 890 (-0.56%)
Mutual labels:  babel

react-native-dotenv

Let you import environment variables from a .env file in React Native, don't need any native code integration.

CircleCI npm version npm downloads

Install

$ npm install react-native-dotenv --save-dev

Add the react-native-dotenv preset to your .babelrc file at the project root.

{
  "presets": ["module:metro-react-native-babel-preset", "module:react-native-dotenv"]
}

If you haven't got .babelrc set up for React Native, remember to install metro-react-native-babel-preset first.

$ npm install metro-react-native-babel-preset --save-dev

Usage

Add your app configuration in an .env file.

API_KEY=lorem
ANOTHER_CONFIG=foobar

Now you can import it in your .js file.

import { API_KEY, ANOTHER_CONFIG } from 'react-native-dotenv'

ApiClient.init(API_KEY, ANOTHER_CONFIG)

How does it work?

As you can see, it's implemented as a babel plugin. All referenced imported members are replaced as the values specified in the .env file.

The example above will get compiled as below.

ApiClient.init('lorem', 'foobar')

FAQ

Changes to .env file is not updated

Manually edit the file importing react-native-dotenv by either adding an empty line or whitespace will work.

Can I use different .env settings for production ?

Yes, simply create a separate .env.production file and the default release process of react-native will pickup the right config.

iOS

You can use the Release configuration to launch the Simulator. (Only supported in RN v0.39+)

react-native run-ios --configuration Release

Android

  1. Command⌘ + M to launch the developer menu in Android emulator.
  2. Tap DevSettings.
  3. Toggle JS Dev Mode.

Can I have more than production & development environment configs?

Sadly, it's not available so far. One of the workaround is generating .env file before triggering RN's bundle script automatically using either shell script or your own custom build pipeline.

Contact

David Chang @zetachang

LICENSE

MIT License, see LICENSE file for detail.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].