forked from rspack-contrib/rspack-vue-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomBlocks.js
44 lines (41 loc) · 1.31 KB
/
customBlocks.js
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
const qs = require('querystring')
const { attrsToQuery, genMatchResource } = require('./utils')
module.exports = function genCustomBlocksCode(
loaderContext,
blocks,
resourcePath,
resourceQuery,
stringifyRequest,
enableInlineMatchResource
) {
return (
`\n/* custom blocks */\n` +
blocks
.map((block, i) => {
const src = block.attrs.src || resourcePath
const attrsQuery = attrsToQuery(block.attrs)
const issuerQuery = block.attrs.src
? `&issuerPath=${qs.escape(resourcePath)}`
: ''
const inheritQuery = resourceQuery ? `&${resourceQuery.slice(1)}` : ''
const externalQuery = block.attrs.src ? `&external` : ``
const query = `?vue&type=custom&index=${i}&blockType=${qs.escape(
block.type
)}${issuerQuery}${attrsQuery}${inheritQuery}${externalQuery}`
let customRequest
if (enableInlineMatchResource) {
customRequest = stringifyRequest(
genMatchResource(loaderContext, src, query, block.attrs.lang)
)
} else {
customRequest = stringifyRequest(src + query)
}
return (
`import block${i} from ${customRequest}\n` +
`if (typeof block${i} === 'function') block${i}(component)`
)
})
.join(`\n`) +
`\n`
)
}