Skip to content

Commit

Permalink
feat: ssr manifest for preload inference
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 18, 2021
1 parent 2527a9d commit 1506285
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function transformMain(
`_sfc_main.__scopeId = ${JSON.stringify(`data-v-${descriptor.id}`)}`
)
}
if (devServer) {
if (devServer && !isProduction) {
// expose filename during serve for devtools to pickup
output.push(`_sfc_main.__file = ${JSON.stringify(filename)}`)
}
Expand All @@ -122,6 +122,21 @@ export async function transformMain(
)
}

// SSR module registration by wrapping user setup
if (ssr) {
output.push(
`import { useSSRContext } from 'vue'`,
`const _sfc_setup = _sfc_main.setup`,
`_sfc_main.setup = (props, ctx) => {`,
` const ssrContext = useSSRContext()`,
` ;(ssrContext.modules || (ssrContext.modules = new Set())).add(${JSON.stringify(
filename
)})`,
` return _sfc_setup ? _sfc_setup(props, ctx) : undefined`,
`}`
)
}

// if the template is inlined into the main module (indicated by the presence
// of templateMap, we need to concatenate the two source maps.
let resolvedMap = map
Expand Down

0 comments on commit 1506285

Please sign in to comment.