Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support post loaders for template blocks #1500

Merged
merged 2 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/loaders/pitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})