From bffacd5ed2d47db8c7e5698f78f3527b95a6b56b Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 24 Apr 2018 17:53:11 -0400 Subject: [PATCH] fix: prioritize .vue rules in plugin (fix #1246) --- lib/plugin.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/plugin.js b/lib/plugin.js index 67ec9181b..afe5d3e15 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -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) {