fix: bring back nuxt3 support

This commit is contained in:
Pooya Parsa 2021-01-18 12:42:00 +01:00
parent b07a4a5c8d
commit 9e9b20ef90
3 changed files with 7 additions and 4 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -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