Commit eab94603 authored by Evan You's avatar Evan You

fix: make sure cloned rules reuse the exact same ident in options

close #1199
parent 343b9df0
...@@ -35,7 +35,7 @@ module.exports = class VueLoaderPlugin { ...@@ -35,7 +35,7 @@ module.exports = class VueLoaderPlugin {
// find the normalized version of the vue rule // find the normalized version of the vue rule
const normalizedVueRule = rawNormalizedRules[vueRuleIndex] const normalizedVueRule = rawNormalizedRules[vueRuleIndex]
// get the normlized "use" for vue files // get the normlized "use" for vue files
const normalizedVueUse = normalizedVueRule.use.map(cleanUse) const normalizedVueUse = normalizedVueRule.use
// get vue-loader options // get vue-loader options
const vueLoaderUseIndex = normalizedVueUse.findIndex(u => { const vueLoaderUseIndex = normalizedVueUse.findIndex(u => {
return /^vue-loader|(\/|\\)vue-loader/.test(u.loader) return /^vue-loader|(\/|\\)vue-loader/.test(u.loader)
...@@ -83,7 +83,7 @@ module.exports = class VueLoaderPlugin { ...@@ -83,7 +83,7 @@ module.exports = class VueLoaderPlugin {
// for each user rule, inject a cloned rule by checking if the rule // for each user rule, inject a cloned rule by checking if the rule
// matches the lang specified in the resourceQuery. // matches the lang specified in the resourceQuery.
rawRules.unshift.apply(rawRules, baseRules.map((rule, i) => { rawRules.unshift.apply(rawRules, baseRules.map((rule, i) => {
return cloneRule(rule, normalizedRules[i], normalizedVueUse) return cloneRule(rule, normalizedRules[i])
})) }))
// inject global pitcher (responsible for injecting template compiler // inject global pitcher (responsible for injecting template compiler
...@@ -91,12 +91,10 @@ module.exports = class VueLoaderPlugin { ...@@ -91,12 +91,10 @@ module.exports = class VueLoaderPlugin {
rawRules.unshift({ rawRules.unshift({
loader: require.resolve('./loaders/pitch') loader: require.resolve('./loaders/pitch')
}) })
// console.log(rawRules)
} }
} }
function cloneRule (rule, normalizedRule, vueUse) { function cloneRule (rule, normalizedRule) {
// Assuming `test` and `resourceQuery` tests are executed in series and // Assuming `test` and `resourceQuery` tests are executed in series and
// synchronously (which is true based on RuleSet's implementation), we can // synchronously (which is true based on RuleSet's implementation), we can
// save the current resource being matched from `test` so that we can access // save the current resource being matched from `test` so that we can access
...@@ -123,13 +121,9 @@ function cloneRule (rule, normalizedRule, vueUse) { ...@@ -123,13 +121,9 @@ function cloneRule (rule, normalizedRule, vueUse) {
} }
return true return true
}, },
use: (normalizedRule.use || []).map(cleanUse) use: normalizedRule.use ? normalizedRule.use.map(reuseIdent) : undefined
}) })
if (!res.use.length) {
delete res.use
}
// delete shorthand since we have normalized use // delete shorthand since we have normalized use
delete res.loader delete res.loader
delete res.loaders delete res.loaders
...@@ -137,17 +131,17 @@ function cloneRule (rule, normalizedRule, vueUse) { ...@@ -137,17 +131,17 @@ function cloneRule (rule, normalizedRule, vueUse) {
if (rule.oneOf) { if (rule.oneOf) {
res.oneOf = rule.oneOf.map((r, i) => { res.oneOf = rule.oneOf.map((r, i) => {
return cloneRule(r, normalizedRule.oneOf[i], vueUse) return cloneRule(r, normalizedRule.oneOf[i])
}) })
} }
return res return res
} }
// "ident" is exposed on normalized uses, delete in case it function reuseIdent (use) {
// interferes with another normalization if (use.ident) {
function cleanUse (use) { use.options.ident = use.ident
const res = Object.assign({}, use) delete use.ident
delete res.ident }
return res return use
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment