This repository was archived by the owner on Jul 8, 2020. It is now read-only.
File tree 1 file changed +19
-7
lines changed
1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -12,20 +12,20 @@ Let you `import` environment variables from a **.env** file in React Native, **d
12
12
$ npm install react-native-dotenv --save-dev
13
13
```
14
14
15
- If you haven't got ** .babelrc** set up for React Native, run
16
-
17
- ``` sh
18
- $ npm install babel-preset-react-native --save-dev
19
- ```
20
-
21
- And create a file named ** .babelrc** as follow in the project root.
15
+ Add the ` react-native-dotenv ` preset to your ** .babelrc** file at the project root.
22
16
23
17
``` json
24
18
{
25
19
"presets" : [" react-native" , " react-native-dotenv" ]
26
20
}
27
21
```
28
22
23
+ If you haven't got ** .babelrc** set up for React Native, remember to install ` babel-preset-react-native ` first.
24
+
25
+ ``` sh
26
+ $ npm install babel-preset-react-native --save-dev
27
+ ```
28
+
29
29
## Usage
30
30
31
31
Add your app configuration in an ** .env** file.
@@ -54,6 +54,18 @@ The example above will get compiled as below.
54
54
ApiClient .init (' lorem' , ' foobar' )
55
55
```
56
56
57
+ ## Can I use different ** .env** settings for production ?
58
+
59
+ Yes, simply create a separate ** .env.production** file and the default release process of react-native will pickup the right config.
60
+
61
+ To test it locally, you can use the ** Release** configuration to launch the Simulator / Emulator.
62
+
63
+ ### iOS
64
+ ` react-native run-ios --configuration Release `
65
+
66
+ ### Android
67
+ ` react-native run-android --configuration Release `
68
+
57
69
## Benefits we got
58
70
59
71
* It could find out error like importing an non-existing variable.
You can’t perform that action at this time.
0 commit comments