Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-dotenv

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-dotenv - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

5

index.js

@@ -0,7 +1,10 @@

var config = require("react-native/packager/rn-cli.config");
module.exports = {
plugins: [
[require('babel-plugin-dotenv'), {
replacedModuleName: 'react-native-dotenv'
replacedModuleName: 'react-native-dotenv',
configDir: config.getProjectRoots()[0]
}],
],
};

6

package.json
{
"name": "react-native-dotenv",
"version": "0.0.2",
"description": "Let you `import` environment variables from a **.env** file in React Native",
"version": "0.0.3",
"description": "A Babel preset let you `import` application configs from **.env** file (zero runtime dependency)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "cd babel-plugin-dotenv && npm install && npm test"
},

@@ -9,0 +9,0 @@ "keywords": [

@@ -5,2 +5,6 @@ # react-native-dotenv

[![CircleCI](https://circleci.com/gh/zetachang/react-native-dotenv.svg?style=svg)](https://circleci.com/gh/zetachang/react-native-dotenv)
[![npm version](https://img.shields.io/npm/v/react-native-dotenv.svg?style=flat-square)](https://www.npmjs.com/package/react-native-dotenv)
[![npm downloads](https://img.shields.io/npm/dt/react-native-dotenv.svg?style=flat-square)](https://www.npmjs.com/package/react-native-dotenv)
## Install

@@ -12,10 +16,4 @@

If you haven't got **.babelrc** set up for React Native, run
Add the `react-native-dotenv` preset to your **.babelrc** file at the project root.
```sh
$ npm install babel-preset-react-native --save-dev
```
And create a file named **.babelrc** as follow in the project root.
```json

@@ -27,5 +25,11 @@ {

If you haven't got **.babelrc** set up for React Native, remember to install `babel-preset-react-native` first.
```sh
$ npm install babel-preset-react-native --save-dev
```
## Usage
Add app configuration in the **.env** file.
Add your app configuration in an **.env** file.

@@ -37,3 +41,3 @@ ```

And import it in your **.js** file.
Now you can import it in your **.js** file.

@@ -48,4 +52,6 @@ ```js

As you can see, it's a babel plugin. It replaces referenced imported members as the values specified in the **.env** file. So the above example will get compiled as below,
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.
```js

@@ -56,10 +62,26 @@

## What we got?
## 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.
To test it locally, you can use the **Release** configuration to launch the Simulator / Emulator.
### iOS
```
react-native run-ios --configuration Release
```
### Android
````
react-native run-android --configuration Release
```
## Benefits we got
* It could find out error like importing an non-existing variable.
![](error.png)
![](https://github.com/zetachang/react-native-dotenv/raw/master/error.png)
* Zero native integration required. (compared to [react-native-config](https://github.com/luggit/react-native-config))
* Since beneath, we use the current [dotenv](https://www.npmjs.com/package/dotenv) package, so the same **.env** file could be reused in nodejs environment.
* Zero native code integration required. (compared to [react-native-config](https://github.com/luggit/react-native-config))
* Given that we use the existing [dotenv](https://www.npmjs.com/package/dotenv) package to parse **.env** file, the same config file could be reused in nodejs environment.

@@ -66,0 +88,0 @@ ## Contact

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc