Commit 731a7ad1 authored by David Guilherme's avatar David Guilherme Committed by Evan You

feat: support post loaders for template blocks (#1500)

parent 4909b170
......@@ -10,6 +10,8 @@ const isNullLoader = l => /(\/|\\|@)null-loader/.test(l.path)
const isCSSLoader = l => /(\/|\\|@)css-loader/.test(l.path)
const isCacheLoader = l => /(\/|\\|@)cache-loader/.test(l.path)
const isPitcher = l => l.path !== __filename
const isPreLoader = l => !l.pitchExecuted
const isPostLoader = l => l.pitchExecuted
const dedupeESLintLoader = loaders => {
const res = []
......@@ -136,10 +138,15 @@ module.exports.pitch = function (remainingRequest) {
cacheIdentifier: hash(cacheIdentifier) + '-vue-loader-template'
})}`]
: []
const preLoaders = loaders.filter(isPreLoader)
const postLoaders = loaders.filter(isPostLoader)
const request = genRequest([
...cacheLoader,
...postLoaders,
templateLoaderPath + `??vue-loader-options`,
...loaders
...preLoaders
])
// console.log(request)
// the template compiler uses esm exports
......
......@@ -305,3 +305,22 @@ test('disable prettify', done => {
done()
})
})
test('postLoaders support', done => {
mockBundleAndRun({
entry: 'basic.vue',
module: {
rules: [
{
resourceQuery: /^\?vue&type=template/,
enforce: 'post',
loader: path.resolve(__dirname, './mock-loaders/html')
}
]
}
}, ({ module }) => {
// class="red" -> { staticClass: "red" } -> { staticClass: "green" }
expect(module.render.toString()).toMatch(`green`)
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