diff --git a/packages/nitro/src/context.ts b/packages/nitro/src/context.ts index 1827ecdbea..b3d6c9df2f 100644 --- a/packages/nitro/src/context.ts +++ b/packages/nitro/src/context.ts @@ -38,6 +38,7 @@ export interface SigmaContext { publicDir: string } _nuxt: { + majorVersion: number dev: boolean rootDir: string srcDir: string @@ -88,6 +89,7 @@ export function getsigmaContext (nuxtOptions: NuxtOptions, input: SigmaInput): S publicDir: '{{ output.dir }}/public' }, _nuxt: { + majorVersion: nuxtOptions._majorVersion || 2, dev: nuxtOptions.dev, rootDir: nuxtOptions.rootDir, srcDir: nuxtOptions.srcDir, diff --git a/packages/nitro/src/rollup/config.ts b/packages/nitro/src/rollup/config.ts index 4723ba03ea..324c2ca8a4 100644 --- a/packages/nitro/src/rollup/config.ts +++ b/packages/nitro/src/rollup/config.ts @@ -159,13 +159,13 @@ export const getRollupConfig = (sigmaContext: SigmaContext) => { })) // https://github.com/rollup/plugins/tree/master/packages/alias - const renderer = sigmaContext.renderer || 'vue2' - const vueServerRenderer = 'vue-server-renderer/' + (sigmaContext._nuxt.dev ? 'build.dev.js' : 'build.prod.js') + const renderer = sigmaContext.renderer || (sigmaContext._nuxt.majorVersion === 3 ? 'vue3' : 'vue2') + const vue2ServerRenderer = 'vue-server-renderer/' + (sigmaContext._nuxt.dev ? 'build.dev.js' : 'build.prod.js') rollupConfig.plugins.push(alias({ entries: { '~runtime': sigmaContext._internal.runtimeDir, '~renderer': require.resolve(resolve(sigmaContext._internal.runtimeDir, 'app', renderer)), - '~vueServerRenderer': vueServerRenderer, + '~vueServerRenderer': vue2ServerRenderer, '~build': sigmaContext._nuxt.buildDir, ...env.alias } diff --git a/packages/nitro/src/runtime/app/render.ts b/packages/nitro/src/runtime/app/render.ts index 1c7552bd5f..80fa655dd4 100644 --- a/packages/nitro/src/runtime/app/render.ts +++ b/packages/nitro/src/runtime/app/render.ts @@ -33,7 +33,8 @@ export async function renderMiddleware (req, res) { ...(req.context || {}) } const rendered = await renderer.renderToString(ssrContext) - const payload = ssrContext.nuxt /* nuxt 2 */ || ssrContext.payload /* nuxt 3 */ + // TODO: nuxt3 should not reuse `nuxt` property for different purpose! + const payload = ssrContext.payload /* nuxt 3 */ || ssrContext.nuxt /* nuxt 2 */ if (process.env.NUXT_FULL_STATIC) { payload.staticAssetsBase = STATIC_ASSETS_BASE