UNPKG

1.2 kBJavaScriptView Raw
1module.exports = function selectBlock (
2 descriptor,
3 loaderContext,
4 query,
5 appendExtension
6) {
7 // template
8 if (query.type === `template`) {
9 if (appendExtension) {
10 loaderContext.resourcePath += '.' + (descriptor.template.lang || 'html')
11 }
12 loaderContext.callback(
13 null,
14 descriptor.template.content,
15 descriptor.template.map
16 )
17 return
18 }
19
20 // script
21 if (query.type === `script`) {
22 if (appendExtension) {
23 loaderContext.resourcePath += '.' + (descriptor.script.lang || 'js')
24 }
25 loaderContext.callback(
26 null,
27 descriptor.script.content,
28 descriptor.script.map
29 )
30 return
31 }
32
33 // styles
34 if (query.type === `style` && query.index != null) {
35 const style = descriptor.styles[query.index]
36 if (appendExtension) {
37 loaderContext.resourcePath += '.' + (style.lang || 'css')
38 }
39 loaderContext.callback(
40 null,
41 style.content,
42 style.map
43 )
44 return
45 }
46
47 // custom
48 if (query.type === 'custom' && query.index != null) {
49 const block = descriptor.customBlocks[query.index]
50 loaderContext.callback(
51 null,
52 block.content,
53 block.map
54 )
55 return
56 }
57}