File tree 6 files changed +22
-1
lines changed
6 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 34
34
"cross-spawn" : " 4.0.0" ,
35
35
"css-loader" : " 0.24.0" ,
36
36
"detect-port" : " 1.0.0" ,
37
+ "dotenv" : " 2.0.0" ,
37
38
"eslint" : " 3.5.0" ,
38
39
"eslint-config-react-app" : " 0.2.0" ,
39
40
"eslint-loader" : " 1.5.0" ,
Original file line number Diff line number Diff line change 12
12
// Do this as the first thing so that any code reading it knows the right env.
13
13
process . env . NODE_ENV = 'production' ;
14
14
15
+ // Load environment variables from .env file. Surpress warnings using silent
16
+ // if this file is missing. dotenv will never modify any environment variables
17
+ // that have already been set.
18
+ // https://github.com/motdotla/dotenv
19
+ require ( 'dotenv' ) . config ( { silent : true } ) ;
20
+
15
21
var chalk = require ( 'chalk' ) ;
16
22
var fs = require ( 'fs-extra' ) ;
17
23
var path = require ( 'path' ) ;
Original file line number Diff line number Diff line change 11
11
12
12
process . env . NODE_ENV = 'development' ;
13
13
14
+ // Load environment variables from .env file. Surpress warnings using silent
15
+ // if this file is missing. dotenv will never modify any environment variables
16
+ // that have already been set.
17
+ // https://github.com/motdotla/dotenv
18
+ require ( 'dotenv' ) . config ( { silent : true } ) ;
19
+
14
20
var path = require ( 'path' ) ;
15
21
var chalk = require ( 'chalk' ) ;
16
22
var webpack = require ( 'webpack' ) ;
Original file line number Diff line number Diff line change 10
10
process . env . NODE_ENV = 'test' ;
11
11
process . env . PUBLIC_URL = '' ;
12
12
13
+ // Load environment variables from .env file. Surpress warnings using silent
14
+ // if this file is missing. dotenv will never modify any environment variables
15
+ // that have already been set.
16
+ // https://github.com/motdotla/dotenv
17
+ require ( 'dotenv' ) . config ( { silent : true } ) ;
18
+
13
19
const createJestConfig = require ( './utils/createJestConfig' ) ;
14
20
const jest = require ( 'jest' ) ;
15
21
const path = require ( 'path' ) ;
Original file line number Diff line number Diff line change @@ -434,7 +434,8 @@ REACT_APP_SECRET_CODE=abcdef npm start
434
434
` ` `
435
435
436
436
> Note: Defining environment variables in this manner is temporary for the life of the shell session. Setting
437
- permanent environment variables is outside the scope of these docs.
437
+ permanent environment variables in development can be done in a ` .env ` file in the root of your project.
438
+ [dotenv](https://github.com/motdotla/dotenv) takes care of loading these for you.
438
439
439
440
With our environment variable defined, we start the app and consume the values. Remember that the ` NODE_ENV `
440
441
variable will be set for you automatically. When you load the app in the browser and inspect the ` < input> ` , you will see
Original file line number Diff line number Diff line change 11
11
12
12
# misc
13
13
.DS_Store
14
+ .env
14
15
npm-debug.log
You can’t perform that action at this time.
0 commit comments