Skip to content

Commit

Permalink
fix: handle vue rule with include (fix #1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 23, 2018
1 parent d3642e2 commit 2be5507
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
34 changes: 34 additions & 0 deletions test/edgeCases.spec.js
Original file line number Diff line number Diff line change
@@ -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'
})

// <h2 class="red">{{msg}}</h2>
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()
})
})

0 comments on commit 2be5507

Please sign in to comment.