Skip to content

Commit 2be5507

Browse files
committed
fix: handle vue rule with include (fix #1201)
1 parent d3642e2 commit 2be5507

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Diff for: lib/plugin.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ module.exports = class VueLoaderPlugin {
1111

1212
// find the rule that applies to vue files
1313
const vueRuleIndex = rawRules.findIndex((rule, i) => {
14-
return !rule.enforce && rawNormalizedRules[i].resource(`foo.vue`)
14+
// #1201 we need to skip the `include` check when locating the vue rule
15+
const clone = Object.assign({}, rule)
16+
delete clone.include
17+
const normalized = RuleSet.normalizeRule(clone)
18+
return !rule.enforce && normalized.resource(`foo.vue`)
1519
})
1620
const vueRule = rawRules[vueRuleIndex]
1721

Diff for: test/edgeCases.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const {
2+
mockRender,
3+
mockBundleAndRun
4+
} = require('./utils')
5+
6+
const normalizeNewline = require('normalize-newline')
7+
8+
test('vue rule with include', done => {
9+
mockBundleAndRun({
10+
entry: 'basic.vue',
11+
modify: config => {
12+
config.module.rules[0] = {
13+
test: /\.vue$/,
14+
include: /fixtures/,
15+
loader: 'vue-loader'
16+
}
17+
}
18+
}, ({ window, module, rawModule }) => {
19+
const vnode = mockRender(module, {
20+
msg: 'hi'
21+
})
22+
23+
// <h2 class="red">{{msg}}</h2>
24+
expect(vnode.tag).toBe('h2')
25+
expect(vnode.data.staticClass).toBe('red')
26+
expect(vnode.children[0].text).toBe('hi')
27+
28+
expect(module.data().msg).toContain('Hello from Component A!')
29+
let style = window.document.querySelector('style').textContent
30+
style = normalizeNewline(style)
31+
expect(style).toContain('comp-a h2 {\n color: #f00;\n}')
32+
done()
33+
})
34+
})

0 commit comments

Comments
 (0)