Skip to content

Commit

Permalink
fix: support usage with other loaders with enforce: post
Browse files Browse the repository at this point in the history
fix #1351
  • Loading branch information
yyx990803 committed Jul 17, 2018
1 parent 791999a commit be2384c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/loaders/pitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ module.exports.pitch = function (remainingRequest) {
const { cacheDirectory, cacheIdentifier } = options
const query = qs.parse(this.resourceQuery.slice(1))

let loaders = this.loaders

// if this is a language block request, remove eslint-loader to avoid
// duplicate linting.
const loaders = query.type
? this.loaders.filter(l => !/(\/|\\|@)eslint-loader/.test(l.path))
: this.loaders
if (query.type) {
loaders = loaders.filter(l => !/(\/|\\|@)eslint-loader/.test(l.path))
}

// remove self
loaders.shift()
loaders = loaders.filter(l => l.path !== __filename)

// do not inject if user uses null-loader to void the type (#1239)
if (loaders.some(l => /(\/|\\|@)null-loader/.test(l.path))) {
Expand Down
32 changes: 30 additions & 2 deletions test/edgeCases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const {
mockBundleAndRun
} = require('./utils')

const assertComponent = ({ window, module }, done) => {
const assertComponent = ({
window,
module,
expectedMsg = 'Hello from Component A!'
}, done) => {
if (typeof module === 'function') {
module = module.options
}
Expand All @@ -23,7 +27,7 @@ const assertComponent = ({ window, module }, done) => {
expect(vnode.data.staticClass).toBe('red')
expect(vnode.children[0].text).toBe('hi')

expect(module.data().msg).toContain('Hello from Component A!')
expect(module.data().msg).toContain(expectedMsg)
let style = window.document.querySelector('style').textContent
style = normalizeNewline(style)
expect(style).toContain('comp-a h2 {\n color: #f00;\n}')
Expand Down Expand Up @@ -184,3 +188,27 @@ test('proper dedupe on src-imports with options', done => {
}
}, res => assertComponent(res, done))
})

// #1351
test('use with postLoader', done => {
mockBundleAndRun({
entry: 'basic.vue',
module: {
rules: [
{
test: /\.js$/,
use: {
loader: require.resolve('./mock-loaders/js')
},
enforce: 'post'
}
]
}
}, ({ window, module }) => {
assertComponent({
window,
module,
expectedMsg: 'Changed!'
}, done)
})
})

0 comments on commit be2384c

Please sign in to comment.