Skip to content

Commit be2384c

Browse files
committed
fix: support usage with other loaders with enforce: post
fix #1351
1 parent 791999a commit be2384c

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

Diff for: lib/loaders/pitcher.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ module.exports.pitch = function (remainingRequest) {
1414
const { cacheDirectory, cacheIdentifier } = options
1515
const query = qs.parse(this.resourceQuery.slice(1))
1616

17+
let loaders = this.loaders
18+
1719
// if this is a language block request, remove eslint-loader to avoid
1820
// duplicate linting.
19-
const loaders = query.type
20-
? this.loaders.filter(l => !/(\/|\\|@)eslint-loader/.test(l.path))
21-
: this.loaders
21+
if (query.type) {
22+
loaders = loaders.filter(l => !/(\/|\\|@)eslint-loader/.test(l.path))
23+
}
2224

2325
// remove self
24-
loaders.shift()
26+
loaders = loaders.filter(l => l.path !== __filename)
2527

2628
// do not inject if user uses null-loader to void the type (#1239)
2729
if (loaders.some(l => /(\/|\\|@)null-loader/.test(l.path))) {

Diff for: test/edgeCases.spec.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const {
99
mockBundleAndRun
1010
} = require('./utils')
1111

12-
const assertComponent = ({ window, module }, done) => {
12+
const assertComponent = ({
13+
window,
14+
module,
15+
expectedMsg = 'Hello from Component A!'
16+
}, done) => {
1317
if (typeof module === 'function') {
1418
module = module.options
1519
}
@@ -23,7 +27,7 @@ const assertComponent = ({ window, module }, done) => {
2327
expect(vnode.data.staticClass).toBe('red')
2428
expect(vnode.children[0].text).toBe('hi')
2529

26-
expect(module.data().msg).toContain('Hello from Component A!')
30+
expect(module.data().msg).toContain(expectedMsg)
2731
let style = window.document.querySelector('style').textContent
2832
style = normalizeNewline(style)
2933
expect(style).toContain('comp-a h2 {\n color: #f00;\n}')
@@ -184,3 +188,27 @@ test('proper dedupe on src-imports with options', done => {
184188
}
185189
}, res => assertComponent(res, done))
186190
})
191+
192+
// #1351
193+
test('use with postLoader', done => {
194+
mockBundleAndRun({
195+
entry: 'basic.vue',
196+
module: {
197+
rules: [
198+
{
199+
test: /\.js$/,
200+
use: {
201+
loader: require.resolve('./mock-loaders/js')
202+
},
203+
enforce: 'post'
204+
}
205+
]
206+
}
207+
}, ({ window, module }) => {
208+
assertComponent({
209+
window,
210+
module,
211+
expectedMsg: 'Changed!'
212+
}, done)
213+
})
214+
})

0 commit comments

Comments
 (0)