Skip to content

Commit

Permalink
fix: prioritize .vue rules in plugin (fix #1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 24, 2018
1 parent 4359bf3 commit bffacd5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,23 @@ module.exports = class VueLoaderPlugin {
// use webpack's RuleSet utility to normalize user rules
const rawNormalizedRules = new RuleSet(rawRules).rules

// find the rule that applies to vue files
const vueRuleIndex = rawRules.findIndex((rule, i) => {
const createMatcher = fakeFile => (rule, i) => {
// #1201 we need to skip the `include` check when locating the vue rule
const clone = Object.assign({}, rule)
delete clone.include
const normalized = RuleSet.normalizeRule(clone, {}, '')
return !rule.enforce && normalized.resource && (
normalized.resource(`foo.vue`) ||
normalized.resource(`foo.vue.html`)
return (
!rule.enforce &&
normalized.resource &&
normalized.resource(fakeFile)
)
})
}

// find the rule that applies to vue files
let vueRuleIndex = rawRules.findIndex(createMatcher(`foo.vue`))
if (vueRuleIndex < 0) {
vueRuleIndex = rawRules.findIndex(createMatcher(`foo.vue.html`))
}
const vueRule = rawRules[vueRuleIndex]

if (!vueRule) {
Expand Down

0 comments on commit bffacd5

Please sign in to comment.