Installations
npm install @madeagency/react-native-dotenv
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
7.10.1
NPM Version
4.2.0
Score
59.4
Supply Chain
87.7
Quality
74.9
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Love this project? Help keep it running — sponsor us today! 🚀
Download Statistics
Total Downloads
1,129
Last Day
2
Last Week
4
Last Month
22
Last Year
111
Bundle Size
1.93 kB
Minified
0.98 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.1.2
Package Id
@madeagency/react-native-dotenv@0.1.2
Size
2.27 kB
NPM Version
4.2.0
Node Version
7.10.1
Total Downloads
Cumulative downloads
Total Downloads
1,129
Last Day
0%
2
Compared to previous day
Last Week
0%
4
Compared to previous week
Last Month
175%
22
Compared to previous month
Last Year
-26.5%
111
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
react-native-dotenv
Let you import
environment variables from a .env file in React Native, don't need any native code integration.
Install
1$ npm install react-native-dotenv --save-dev
Add the react-native-dotenv
preset to your .babelrc file at the project root.
1{ 2 "presets": ["react-native", "react-native-dotenv"] 3}
If you haven't got .babelrc set up for React Native, remember to install babel-preset-react-native
first.
1$ npm install babel-preset-react-native --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.
1import { API_KEY, ANOTHER_CONFIG } from 'react-native-dotenv' 2 3ApiClient.init(API_KEY, ANOTHER_CONFIG)
How does it works?
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.
1 2ApiClient.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
Command⌘
+M
to launch the developer menu in Android emulator.- Tap DevSettings.
- 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
LICENSE
MIT License, see LICENSE file for detail.

No vulnerabilities found.

No security vulnerabilities found.