-
Notifications
You must be signed in to change notification settings - Fork 915
/
Copy pathselect.ts
48 lines (44 loc) · 1.44 KB
/
select.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import webpack from 'webpack'
import { SFCDescriptor } from '@vue/compiler-sfc'
import { ParsedUrlQuery } from 'querystring'
export function selectBlock(
descriptor: SFCDescriptor,
loaderContext: webpack.loader.LoaderContext,
query: ParsedUrlQuery,
appendExtension: boolean
) {
// template
if (query.type === `template`) {
// if we are receiving a query with type it can only come from a *.vue file
// that contains that block, so the block is guaranteed to exist.
const template = descriptor.template!
if (appendExtension) {
loaderContext.resourcePath += '.' + (template.lang || 'html')
}
loaderContext.callback(null, template.content, template.map)
return
}
// script
if (query.type === `script`) {
const script = (descriptor as any).scriptCompiled
if (appendExtension) {
loaderContext.resourcePath += '.' + (script.lang || 'js')
}
loaderContext.callback(null, script.content, script.map)
return
}
// styles
if (query.type === `style` && query.index != null) {
const style = descriptor.styles[Number(query.index)]
if (appendExtension) {
loaderContext.resourcePath += '.' + (style.lang || 'css')
}
loaderContext.callback(null, style.content, style.map)
return
}
// custom
if (query.type === 'custom' && query.index != null) {
const block = descriptor.customBlocks[Number(query.index)]
loaderContext.callback(null, block.content, block.map)
}
}