File tree 4 files changed +1708
-713
lines changed
4 files changed +1708
-713
lines changed Original file line number Diff line number Diff line change 2
2
3
3
Monorepo containing setup for a best-practice React application scaffolding
4
4
5
+ ### ENV variables
6
+
7
+ You can use environment variables to configure build scripts.
8
+
9
+ Here's the list of supported variables with their defaults:
10
+
11
+ ```
12
+ SOURCE_DIR=src
13
+ BUILD_DIR=build
14
+ SOURCEMAPS=false
15
+ ```
16
+
17
+ You can override any of these variables with ` .env ` files. We support these formats (in the order of inclusion):
18
+
19
+ ```
20
+ .env.${NODE_ENV}.local
21
+ .env.${NODE_ENV}
22
+ .env.local
23
+ .env
24
+ ```
25
+
26
+ The order of inclusion means that anything in ` .env ` will override content in e.g. ` .env.development.local ` .
27
+
5
28
### DLLs
6
29
7
30
DLLs precompile libraries to save time for development builds and re-builds.
Original file line number Diff line number Diff line change 3
3
"version" : " 0.0.4" ,
4
4
"description" : " Modus React App Scaffolding" ,
5
5
"bin" : " bin/more.js" ,
6
+ "engines" : {
7
+ "node" : " >=8.9.3"
8
+ },
6
9
"scripts" : {
7
10
"test" : " echo \" Error: no test specified\" && exit 1"
8
11
},
23
26
"cross-spawn" : " ^6.0.5" ,
24
27
"css-loader" : " 1.0.1" ,
25
28
"dotenv" : " ^6.2.0" ,
29
+ "dotenv-expand" : " ^4.2.0" ,
26
30
"eslint" : " 5.9.0" ,
27
31
"file-loader" : " 2.0.0" ,
28
32
"find-file-up" : " ^2.0.1" ,
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' ) ;
1
2
const path = require ( 'path' ) ;
2
- const find = require ( 'find-file-up' ) ;
3
+ const expand = require ( 'dotenv-expand' ) ;
4
+ const dotenv = require ( 'dotenv' ) ;
3
5
4
- // Find .env or .env.local
5
- const envFile =
6
- find . sync ( '.env' ) ||
7
- find . sync ( '.env.local' ) ||
8
- path . resolve ( __dirname , '..' , '.env.local' ) ;
6
+ const { NODE_ENV , INIT_CWD : projectRoot } = process . env ;
9
7
10
- require ( 'dotenv' ) . config ( { path : envFile } ) ;
8
+ const dotenvFiles = [
9
+ path . resolve ( __dirname , '..' , '.env.local' ) ,
10
+ path . join ( projectRoot , `.env.${ NODE_ENV } .local` ) ,
11
+ path . join ( projectRoot , `.env.${ NODE_ENV } ` ) ,
12
+ NODE_ENV !== 'test' && path . join ( projectRoot , `.env.local` ) ,
13
+ path . join ( projectRoot , `.env` ) ,
14
+ ] . filter ( Boolean ) ;
15
+
16
+ // Load environment variables from .env* files.
17
+ // Use local .env as defaults
18
+ dotenvFiles . forEach ( dotenvFile => {
19
+ if ( fs . existsSync ( dotenvFile ) ) {
20
+ expand (
21
+ dotenv . config ( {
22
+ path : dotenvFile ,
23
+ } )
24
+ ) ;
25
+ }
26
+ } ) ;
You can’t perform that action at this time.
0 commit comments