Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 1c4c510

Browse files
committed
fix: add extension to Vue block URI
1 parent b3cbb52 commit 1c4c510

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

Diff for: src/index.ts

+30-5
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ type Query =
280280
}
281281

282282
function parseVuePartRequest(id: string): Query {
283-
const [filename, query] = id.split('?', 2)
283+
const [filename, query] = id.replace(/#\.[\w-]+$/, '').split('?', 2)
284284

285285
if (!query) return { vue: false, filename }
286286

@@ -391,7 +391,12 @@ function getTemplateCode(
391391
const scopedQuery = hasScoped ? `&scoped=true` : ``
392392
const srcQuery = descriptor.template.src ? `&src` : ``
393393
const attrsQuery = attrsToQuery(descriptor.template.attrs)
394-
const query = `?vue&type=template${idQuery}${srcQuery}${scopedQuery}${attrsQuery}`
394+
const ext = extensionFragment(
395+
'template',
396+
descriptor.template.attrs.lang as string,
397+
'html'
398+
)
399+
const query = `?vue&type=template${idQuery}${srcQuery}${scopedQuery}${attrsQuery}${ext}`
395400
templateRequest = _(src + query)
396401
templateImport = `import { ${
397402
isServer ? 'ssrRender' : 'render'
@@ -407,7 +412,12 @@ function getScriptCode(descriptor: SFCDescriptor, resourcePath: string) {
407412
const src = descriptor.script.src || resourcePath
408413
const attrsQuery = attrsToQuery(descriptor.script.attrs, 'js')
409414
const srcQuery = descriptor.script.src ? `&src` : ``
410-
const query = `?vue&type=script${srcQuery}${attrsQuery}`
415+
const ext = extensionFragment(
416+
'script',
417+
descriptor.script.attrs.lang as string,
418+
'js'
419+
)
420+
const query = `?vue&type=script${srcQuery}${attrsQuery}${ext}`
411421
const scriptRequest = _(src + query)
412422
scriptImport =
413423
`import script from ${scriptRequest}\n` + `export * from ${scriptRequest}` // support named exports
@@ -435,8 +445,14 @@ function getStyleCode(
435445
const idQuery = style.scoped ? `&id=${id}` : ``
436446
const srcQuery = style.src ? `&src` : ``
437447
const query = `?vue&type=style&index=${i}${srcQuery}${idQuery}`
438-
const styleRequest = src + query + attrsQuery
439-
const styleRequestWithoutModule = src + query + attrsQueryWithoutModule
448+
const ext = extensionFragment(
449+
'template',
450+
style.attrs.lang as string,
451+
'html'
452+
)
453+
const styleRequest = src + query + attrsQuery + ext
454+
const styleRequestWithoutModule =
455+
src + query + attrsQueryWithoutModule + ext
440456
if (style.module) {
441457
if (!hasCSSModules) {
442458
stylesCode += `\nconst cssModules = script.__cssModules = {}`
@@ -479,6 +495,15 @@ function createRollupError(id: string, error: CompilerError): RollupError {
479495
// these are built-in query parameters so should be ignored
480496
// if the user happen to add them as attrs
481497
const ignoreList = ['id', 'index', 'src', 'type']
498+
499+
function extensionFragment(
500+
block: string,
501+
lang?: string,
502+
langFallback?: string
503+
) {
504+
return `#.${lang || langFallback || block}`
505+
}
506+
482507
function attrsToQuery(
483508
attrs: SFCBlock['attrs'],
484509
langFallback?: string,

0 commit comments

Comments
 (0)