Skip to content

Commit

Permalink
fix: make sure cloned rules reuse the exact same ident in options
Browse files Browse the repository at this point in the history
close #1199
  • Loading branch information
yyx990803 committed Mar 23, 2018
1 parent 343b9df commit eab9460
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = class VueLoaderPlugin {
// find the normalized version of the vue rule
const normalizedVueRule = rawNormalizedRules[vueRuleIndex]
// get the normlized "use" for vue files
const normalizedVueUse = normalizedVueRule.use.map(cleanUse)
const normalizedVueUse = normalizedVueRule.use
// get vue-loader options
const vueLoaderUseIndex = normalizedVueUse.findIndex(u => {
return /^vue-loader|(\/|\\)vue-loader/.test(u.loader)
Expand Down Expand Up @@ -83,20 +83,18 @@ module.exports = class VueLoaderPlugin {
// for each user rule, inject a cloned rule by checking if the rule
// matches the lang specified in the resourceQuery.
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
// loader & CSS post loader)
rawRules.unshift({
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
// synchronously (which is true based on RuleSet's implementation), we can
// save the current resource being matched from `test` so that we can access
Expand All @@ -123,31 +121,27 @@ function cloneRule (rule, normalizedRule, vueUse) {
}
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 res.loader
delete res.loaders
delete res.options

if (rule.oneOf) {
res.oneOf = rule.oneOf.map((r, i) => {
return cloneRule(r, normalizedRule.oneOf[i], vueUse)
return cloneRule(r, normalizedRule.oneOf[i])
})
}

return res
}

// "ident" is exposed on normalized uses, delete in case it
// interferes with another normalization
function cleanUse (use) {
const res = Object.assign({}, use)
delete res.ident
return res
function reuseIdent (use) {
if (use.ident) {
use.options.ident = use.ident
delete use.ident
}
return use
}

0 comments on commit eab9460

Please sign in to comment.