diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index b9fea628..e59fcfe0 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -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)}`) } @@ -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