File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
packages/@vue/cli-service Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,11 @@ beforeEach(() => {
2626} )
2727
2828test ( '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` )
3132 createMockService ( )
32- expect ( process . env . FOO ) . toBe ( '3 ' )
33+ expect ( process . env . FOO ) . toBe ( '0 ' )
3334 expect ( process . env . BAR ) . toBe ( '2' )
3435 expect ( process . env . BAZ ) . toBe ( '4' )
3536} )
Original file line number Diff line number Diff line change @@ -53,12 +53,12 @@ module.exports = class Service {
5353 this . initialized = true
5454 this . mode = mode
5555
56- // load base .env
57- this . loadEnv ( )
5856 // load mode .env
5957 if ( mode ) {
6058 this . loadEnv ( mode )
6159 }
60+ // load base .env
61+ this . loadEnv ( )
6262
6363 // load user config
6464 const userOptions = this . loadUserOptions ( )
@@ -106,8 +106,8 @@ module.exports = class Service {
106106 }
107107 }
108108
109- load ( basePath )
110109 load ( localPath )
110+ load ( basePath )
111111 }
112112
113113 resolvePlugins ( inlinePlugins , useBuiltIn ) {
Original file line number Diff line number Diff line change @@ -3,7 +3,9 @@ const fs = require('fs')
33module . exports = function loadEnv ( path = '.env' ) {
44 const config = parse ( fs . readFileSync ( path , 'utf-8' ) )
55 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+ }
79 } )
810 return config
911}
You can’t perform that action at this time.
0 commit comments