fix: preserve rule names when configureWebpack is present

close #2206
This commit is contained in:
Evan You
2018-08-14 10:05:15 -04:00
parent 69a4fb3ad7
commit 2257034141
+25 -1
View File
@@ -216,6 +216,7 @@ module.exports = class Service {
}
// get raw config
let config = chainableConfig.toConfig()
const original = config
// apply raw config fns
this.webpackRawConfigFns.forEach(fn => {
if (typeof fn === 'function') {
@@ -228,6 +229,16 @@ module.exports = class Service {
}
})
// #2206 If config is merged by merge-webpack, it discards the __ruleNames
// information injected by webpack-chain. Restore the info so that
// vue inspect works properly.
if (config !== original) {
cloneRuleNames(
config.module.rules,
original.module.rules
)
}
// check if the user has manually mutated output.publicPath
const target = process.env.VUE_CLI_BUILD_TARGET
if (
@@ -298,10 +309,10 @@ module.exports = class Service {
}
// normalize some options
ensureSlash(resolved, 'baseUrl')
if (typeof resolved.baseUrl === 'string') {
resolved.baseUrl = resolved.baseUrl.replace(/^\.\//, '')
}
ensureSlash(resolved, 'baseUrl')
removeSlash(resolved, 'outputDir')
// deprecation warning
@@ -339,3 +350,16 @@ function removeSlash (config, key) {
config[key] = config[key].replace(/\/$/g, '')
}
}
function cloneRuleNames (to, from) {
from.forEach((r, i) => {
if (to[i]) {
Object.defineProperty(to[i], '__ruleNames', {
value: r.__ruleNames
})
if (to[i].oneOf && r.oneOf) {
cloneRuleNames(to[i].oneOf, r.oneOf)
}
}
})
}