diff --git a/lib/plugin.js b/lib/plugin.js index 6e159719b..81337bf3c 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -11,7 +11,11 @@ module.exports = class VueLoaderPlugin { // find the rule that applies to vue files const vueRuleIndex = rawRules.findIndex((rule, i) => { - return !rule.enforce && rawNormalizedRules[i].resource(`foo.vue`) + // #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(`foo.vue`) }) const vueRule = rawRules[vueRuleIndex] diff --git a/test/edgeCases.spec.js b/test/edgeCases.spec.js new file mode 100644 index 000000000..96661a628 --- /dev/null +++ b/test/edgeCases.spec.js @@ -0,0 +1,34 @@ +const { + mockRender, + mockBundleAndRun +} = require('./utils') + +const normalizeNewline = require('normalize-newline') + +test('vue rule with include', done => { + mockBundleAndRun({ + entry: 'basic.vue', + modify: config => { + config.module.rules[0] = { + test: /\.vue$/, + include: /fixtures/, + loader: 'vue-loader' + } + } + }, ({ window, module, rawModule }) => { + const vnode = mockRender(module, { + msg: 'hi' + }) + + //

{{msg}}

+ expect(vnode.tag).toBe('h2') + expect(vnode.data.staticClass).toBe('red') + expect(vnode.children[0].text).toBe('hi') + + expect(module.data().msg).toContain('Hello from Component A!') + let style = window.document.querySelector('style').textContent + style = normalizeNewline(style) + expect(style).toContain('comp-a h2 {\n color: #f00;\n}') + done() + }) +})