@@ -69,6 +69,8 @@ export async function transformMain(
6969 // feature information
7070 const attachedProps : [ string , string ] [ ] = [ ]
7171 const hasScoped = descriptor . styles . some ( ( s ) => s . scoped )
72+ const isTemplateOnlyVapor =
73+ ! descriptor . script && ! descriptor . scriptSetup && descriptor . vapor
7274
7375 // script
7476 const { code : scriptCode , map : scriptMap } = await genScriptCode (
@@ -81,11 +83,20 @@ export async function transformMain(
8183 // template
8284 const hasTemplateImport =
8385 descriptor . template && ! isUseInlineTemplate ( descriptor , options )
86+ const isTemplateInlined =
87+ ! ! descriptor . template &&
88+ ( ! descriptor . template . lang || descriptor . template . lang === 'html' ) &&
89+ ! descriptor . template . src
8490
8591 let templateCode = ''
8692 let templateMap : RawSourceMap | undefined
93+ let templateMultiRoot : boolean | undefined
8794 if ( hasTemplateImport ) {
88- ; ( { code : templateCode , map : templateMap } = await genTemplateCode (
95+ ; ( {
96+ code : templateCode ,
97+ map : templateMap ,
98+ multiRoot : templateMultiRoot ,
99+ } = await genTemplateCode (
89100 descriptor ,
90101 options ,
91102 pluginContext ,
@@ -120,6 +131,11 @@ export async function transformMain(
120131 const output : string [ ] = [
121132 scriptCode ,
122133 templateCode ,
134+ isTemplateOnlyVapor
135+ ? `${ scriptIdentifier } .__multiRoot = ${
136+ isTemplateInlined ? templateMultiRoot : '_sfc_multiRoot'
137+ } `
138+ : '' ,
123139 stylesCode ,
124140 customBlocksCode ,
125141 ]
@@ -295,21 +311,31 @@ async function genTemplateCode(
295311 options : ResolvedOptions ,
296312 pluginContext : Context ,
297313 customElement : boolean ,
298- ) {
314+ ) : Promise < {
315+ code : string
316+ map ?: RawSourceMap
317+ multiRoot ?: boolean
318+ } > {
299319 const template = descriptor . template !
300320 const hasScoped = descriptor . styles . some ( ( style ) => style . scoped )
321+ const needsMultiRoot =
322+ ! descriptor . script && ! descriptor . scriptSetup && descriptor . vapor
301323
302324 // If the template is not using pre-processor AND is not using external src,
303325 // compile and inline it directly in the main module. When served in vite this
304326 // saves an extra request per SFC which can improve load performance.
305327 if ( ( ! template . lang || template . lang === 'html' ) && ! template . src ) {
306- return transformTemplateInMain (
328+ const result = transformTemplateInMain (
307329 template . content ,
308330 descriptor ,
309331 options ,
310332 pluginContext ,
311333 customElement ,
312334 )
335+ return {
336+ ...result ,
337+ multiRoot : needsMultiRoot ? result . multiRoot : undefined ,
338+ }
313339 } else {
314340 if ( template . src ) {
315341 await linkSrcToDescriptor (
@@ -331,7 +357,9 @@ async function genTemplateCode(
331357 const request = JSON . stringify ( src + query )
332358 const renderFnName = options . ssr ? 'ssrRender' : 'render'
333359 return {
334- code : `import { ${ renderFnName } as _sfc_${ renderFnName } } from ${ request } ` ,
360+ code : `import { ${ renderFnName } as _sfc_${ renderFnName } ${
361+ needsMultiRoot ? ', multiRoot as _sfc_multiRoot' : ''
362+ } } from ${ request } `,
335363 map : undefined ,
336364 }
337365 }
0 commit comments