Skip to content

Commit a7f3c2c

Browse files
author
Guillaume Chau
committed
fix(invoke): deep merge only plain objects
1 parent 35cb714 commit a7f3c2c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/@vue/cli/lib/util/configTransforms.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const stringifyJS = require('./stringifyJS')
33
const { loadModule } = require('./module')
44
const merge = require('deepmerge')
55

6+
const isObject = val => val && typeof val === 'object'
7+
68
function makeJSTransform (filename) {
79
return function transformToJS (value, checkExisting, files, context) {
810
if (checkExisting && files[filename]) {
@@ -12,7 +14,15 @@ function makeJSTransform (filename) {
1214
const originalData = loadModule(filename, context, true)
1315
// We merge only the modified keys
1416
Object.keys(value).forEach(key => {
15-
changedData[key] = merge(originalData[key], value[key])
17+
const originalValue = originalData[key]
18+
const newValue = value[key]
19+
if (Array.isArray(newValue)) {
20+
changedData[key] = newValue
21+
} else if (isObject(originalValue) && isObject(newValue)) {
22+
changedData[key] = merge(originalValue, newValue)
23+
} else {
24+
changedData[key] = newValue
25+
}
1626
})
1727
} catch (e) {
1828
changedData = value

0 commit comments

Comments
 (0)