Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "rn-dotenv", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A Babel preset let you `import` application configs from **.env** file (zero runtime dependency)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# rn-dotenv | ||
Let you `import` environment variables from a **.env** file in React Native, **don't** need any native code integration. | ||
# NOTE: [npm babel-plugin-dotenv-import](https://github.com/tusbar/babel-plugin-dotenv-import) is the new rewrite location | ||
[![CircleCI](https://circleci.com/gh/zetachang/rn-dotenv.svg?style=svg)](https://circleci.com/gh/zetachang/rn-dotenv) | ||
Let you `import` environment variables from a **.env** file in React Native, **don't** need any native code integration. This is the maintained fork of the abandoned repository. | ||
[![CircleCI](https://circleci.com/gh/goatandsheep/rn-dotenv.svg?style=svg)](https://circleci.com/gh/goatandsheep/rn-dotenv) | ||
[![npm version](https://img.shields.io/npm/v/rn-dotenv.svg?style=flat-square)](https://www.npmjs.com/package/rn-dotenv) | ||
@@ -29,2 +31,10 @@ [![npm downloads](https://img.shields.io/npm/dt/rn-dotenv.svg?style=flat-square)](https://www.npmjs.com/package/rn-dotenv) | ||
You may have to reset cache before this works: | ||
```sh | ||
$ npm start -- --reset-cache | ||
$ yarn start --reset-cache | ||
$ npx react-native start --reset-cache | ||
``` | ||
## Usage | ||
@@ -47,2 +57,23 @@ | ||
### Typescript | ||
If you're using this in a Typescript react native project, Typescript will complain that the named import does not exist in the package. | ||
Here's a solution to solve the problem. | ||
Steps | ||
1. Create a file `env.d.ts` (The filename doesn't matter, as long it ends with `.d.ts`) | ||
2. In the file write the following (for this example, I'll use `API_KEY` as the environment variable) | ||
```ts | ||
declare module 'react-native-dotenv' { | ||
/** | ||
* API key | ||
*/ | ||
export const API_KEY: string; | ||
} | ||
``` | ||
3. Now import the enviornment variable and your good to go. Ex: ` import { API_KEY } from 'react-native-dotenv'` | ||
Solution provided by https://github.com/zetachang/react-native-dotenv/issues/76#issuecomment-585171009 | ||
## How does it work? | ||
@@ -86,6 +117,9 @@ | ||
### How do I use this with Continuous Integration? | ||
When using a CI tool you will have to write the environment variables to the `.env` file. In Github Actions you may for example add a line like `echo -e "${{ secrets.DOTENV }}" > .env`. | ||
## Contact | ||
[David Chang](http://github.com/zetachang) | ||
[@zetachang](https://twitter.com/zetachang) | ||
[Kemal Ahmed](http://github.com/goatandsheep) | ||
@@ -92,0 +126,0 @@ ## LICENSE |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
7090
6
126