Skip to content

Commit 1506285

Browse files
committed
feat: ssr manifest for preload inference
1 parent 2527a9d commit 1506285

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/plugin-vue/src/main.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function transformMain(
9595
`_sfc_main.__scopeId = ${JSON.stringify(`data-v-${descriptor.id}`)}`
9696
)
9797
}
98-
if (devServer) {
98+
if (devServer && !isProduction) {
9999
// expose filename during serve for devtools to pickup
100100
output.push(`_sfc_main.__file = ${JSON.stringify(filename)}`)
101101
}
@@ -122,6 +122,21 @@ export async function transformMain(
122122
)
123123
}
124124

125+
// SSR module registration by wrapping user setup
126+
if (ssr) {
127+
output.push(
128+
`import { useSSRContext } from 'vue'`,
129+
`const _sfc_setup = _sfc_main.setup`,
130+
`_sfc_main.setup = (props, ctx) => {`,
131+
` const ssrContext = useSSRContext()`,
132+
` ;(ssrContext.modules || (ssrContext.modules = new Set())).add(${JSON.stringify(
133+
filename
134+
)})`,
135+
` return _sfc_setup ? _sfc_setup(props, ctx) : undefined`,
136+
`}`
137+
)
138+
}
139+
125140
// if the template is inlined into the main module (indicated by the presence
126141
// of templateMap, we need to concatenate the two source maps.
127142
let resolvedMap = map

0 commit comments

Comments
 (0)