Skip to content

Commit 731a7ad

Browse files
davidguilhermeyyx990803
authored andcommitted
feat: support post loaders for template blocks (#1500)
1 parent 4909b17 commit 731a7ad

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Diff for: lib/loaders/pitcher.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const isNullLoader = l => /(\/|\\|@)null-loader/.test(l.path)
1010
const isCSSLoader = l => /(\/|\\|@)css-loader/.test(l.path)
1111
const isCacheLoader = l => /(\/|\\|@)cache-loader/.test(l.path)
1212
const isPitcher = l => l.path !== __filename
13+
const isPreLoader = l => !l.pitchExecuted
14+
const isPostLoader = l => l.pitchExecuted
1315

1416
const dedupeESLintLoader = loaders => {
1517
const res = []
@@ -136,10 +138,15 @@ module.exports.pitch = function (remainingRequest) {
136138
cacheIdentifier: hash(cacheIdentifier) + '-vue-loader-template'
137139
})}`]
138140
: []
141+
142+
const preLoaders = loaders.filter(isPreLoader)
143+
const postLoaders = loaders.filter(isPostLoader)
144+
139145
const request = genRequest([
140146
...cacheLoader,
147+
...postLoaders,
141148
templateLoaderPath + `??vue-loader-options`,
142-
...loaders
149+
...preLoaders
143150
])
144151
// console.log(request)
145152
// the template compiler uses esm exports

Diff for: test/template.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,22 @@ test('disable prettify', done => {
305305
done()
306306
})
307307
})
308+
309+
test('postLoaders support', done => {
310+
mockBundleAndRun({
311+
entry: 'basic.vue',
312+
module: {
313+
rules: [
314+
{
315+
resourceQuery: /^\?vue&type=template/,
316+
enforce: 'post',
317+
loader: path.resolve(__dirname, './mock-loaders/html')
318+
}
319+
]
320+
}
321+
}, ({ module }) => {
322+
// class="red" -> { staticClass: "red" } -> { staticClass: "green" }
323+
expect(module.render.toString()).toMatch(`green`)
324+
done()
325+
})
326+
})

0 commit comments

Comments
 (0)