react-native-dotenv
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -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] | ||
}], | ||
], | ||
}; |
{ | ||
"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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
4328
9
2
90