Skip to content

Commit 2257034

Browse files
committed
fix: preserve rule names when configureWebpack is present
close vuejs#2206
1 parent 69a4fb3 commit 2257034

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ module.exports = class Service {
216216
}
217217
// get raw config
218218
let config = chainableConfig.toConfig()
219+
const original = config
219220
// apply raw config fns
220221
this.webpackRawConfigFns.forEach(fn => {
221222
if (typeof fn === 'function') {
@@ -228,6 +229,16 @@ module.exports = class Service {
228229
}
229230
})
230231

232+
// #2206 If config is merged by merge-webpack, it discards the __ruleNames
233+
// information injected by webpack-chain. Restore the info so that
234+
// vue inspect works properly.
235+
if (config !== original) {
236+
cloneRuleNames(
237+
config.module.rules,
238+
original.module.rules
239+
)
240+
}
241+
231242
// check if the user has manually mutated output.publicPath
232243
const target = process.env.VUE_CLI_BUILD_TARGET
233244
if (
@@ -298,10 +309,10 @@ module.exports = class Service {
298309
}
299310

300311
// normalize some options
301-
ensureSlash(resolved, 'baseUrl')
302312
if (typeof resolved.baseUrl === 'string') {
303313
resolved.baseUrl = resolved.baseUrl.replace(/^\.\//, '')
304314
}
315+
ensureSlash(resolved, 'baseUrl')
305316
removeSlash(resolved, 'outputDir')
306317

307318
// deprecation warning
@@ -339,3 +350,16 @@ function removeSlash (config, key) {
339350
config[key] = config[key].replace(/\/$/g, '')
340351
}
341352
}
353+
354+
function cloneRuleNames (to, from) {
355+
from.forEach((r, i) => {
356+
if (to[i]) {
357+
Object.defineProperty(to[i], '__ruleNames', {
358+
value: r.__ruleNames
359+
})
360+
if (to[i].oneOf && r.oneOf) {
361+
cloneRuleNames(to[i].oneOf, r.oneOf)
362+
}
363+
}
364+
})
365+
}

0 commit comments

Comments
 (0)