Skip to content

Commit 1723792

Browse files
committed
fix(env): preserve existing env vars so load in reverse order.
Fixes #1499
1 parent 5c8dd98 commit 1723792

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/@vue/cli-service/lib/Service.js

+3-3
Original file line numberDiff line numberDiff 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) {

packages/@vue/cli-service/lib/util/loadEnv.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const fs = require('fs')
33
module.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
}

0 commit comments

Comments
 (0)