Commit be2384c2 authored by Evan You's avatar Evan You

fix: support usage with other loaders with enforce: post

fix #1351
parent 791999a2
...@@ -14,14 +14,16 @@ module.exports.pitch = function (remainingRequest) { ...@@ -14,14 +14,16 @@ module.exports.pitch = function (remainingRequest) {
const { cacheDirectory, cacheIdentifier } = options const { cacheDirectory, cacheIdentifier } = options
const query = qs.parse(this.resourceQuery.slice(1)) const query = qs.parse(this.resourceQuery.slice(1))
let loaders = this.loaders
// if this is a language block request, remove eslint-loader to avoid // if this is a language block request, remove eslint-loader to avoid
// duplicate linting. // duplicate linting.
const loaders = query.type if (query.type) {
? this.loaders.filter(l => !/(\/|\\|@)eslint-loader/.test(l.path)) loaders = loaders.filter(l => !/(\/|\\|@)eslint-loader/.test(l.path))
: this.loaders }
// remove self // remove self
loaders.shift() loaders = loaders.filter(l => l.path !== __filename)
// do not inject if user uses null-loader to void the type (#1239) // do not inject if user uses null-loader to void the type (#1239)
if (loaders.some(l => /(\/|\\|@)null-loader/.test(l.path))) { if (loaders.some(l => /(\/|\\|@)null-loader/.test(l.path))) {
......
...@@ -9,7 +9,11 @@ const { ...@@ -9,7 +9,11 @@ const {
mockBundleAndRun mockBundleAndRun
} = require('./utils') } = require('./utils')
const assertComponent = ({ window, module }, done) => { const assertComponent = ({
window,
module,
expectedMsg = 'Hello from Component A!'
}, done) => {
if (typeof module === 'function') { if (typeof module === 'function') {
module = module.options module = module.options
} }
...@@ -23,7 +27,7 @@ const assertComponent = ({ window, module }, done) => { ...@@ -23,7 +27,7 @@ const assertComponent = ({ window, module }, done) => {
expect(vnode.data.staticClass).toBe('red') expect(vnode.data.staticClass).toBe('red')
expect(vnode.children[0].text).toBe('hi') 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 let style = window.document.querySelector('style').textContent
style = normalizeNewline(style) style = normalizeNewline(style)
expect(style).toContain('comp-a h2 {\n color: #f00;\n}') expect(style).toContain('comp-a h2 {\n color: #f00;\n}')
...@@ -184,3 +188,27 @@ test('proper dedupe on src-imports with options', done => { ...@@ -184,3 +188,27 @@ test('proper dedupe on src-imports with options', done => {
} }
}, res => assertComponent(res, 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)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment