File tree 3 files changed +10
-7
lines changed
packages/@vue/cli-service 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,11 @@ beforeEach(() => {
26
26
} )
27
27
28
28
test ( 'env loading' , ( ) => {
29
- fs . writeFileSync ( '/.env' , `FOO=1\nBAR=2` )
30
- fs . writeFileSync ( '/.env.local' , `FOO=3\nBAZ=4` )
29
+ process . env . FOO = 0
30
+ fs . writeFileSync ( '/.env.local' , `FOO=1\nBAR=2` )
31
+ fs . writeFileSync ( '/.env' , `BAR=3\nBAZ=4` )
31
32
createMockService ( )
32
- expect ( process . env . FOO ) . toBe ( '3 ' )
33
+ expect ( process . env . FOO ) . toBe ( '0 ' )
33
34
expect ( process . env . BAR ) . toBe ( '2' )
34
35
expect ( process . env . BAZ ) . toBe ( '4' )
35
36
} )
Original file line number Diff line number Diff line change @@ -53,12 +53,12 @@ module.exports = class Service {
53
53
this . initialized = true
54
54
this . mode = mode
55
55
56
- // load base .env
57
- this . loadEnv ( )
58
56
// load mode .env
59
57
if ( mode ) {
60
58
this . loadEnv ( mode )
61
59
}
60
+ // load base .env
61
+ this . loadEnv ( )
62
62
63
63
// load user config
64
64
const userOptions = this . loadUserOptions ( )
@@ -106,8 +106,8 @@ module.exports = class Service {
106
106
}
107
107
}
108
108
109
- load ( basePath )
110
109
load ( localPath )
110
+ load ( basePath )
111
111
}
112
112
113
113
resolvePlugins ( inlinePlugins , useBuiltIn ) {
Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ const fs = require('fs')
3
3
module . exports = function loadEnv ( path = '.env' ) {
4
4
const config = parse ( fs . readFileSync ( path , 'utf-8' ) )
5
5
Object . keys ( config ) . forEach ( key => {
6
- process . env [ key ] = config [ key ]
6
+ if ( typeof process . env [ key ] === 'undefined' ) {
7
+ process . env [ key ] = config [ key ]
8
+ }
7
9
} )
8
10
return config
9
11
}
You can’t perform that action at this time.
0 commit comments