fix(nitro): fix rendering with ssr disabled (#2191)

This commit is contained in:
Ajai 2021-12-06 05:48:12 -05:00 committed by GitHub
parent 87db67181f
commit 1c88580c8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,7 @@ const NUXT_NO_SSR = process.env.NUXT_NO_SSR
const PAYLOAD_JS = '/payload.js'
const getClientManifest = cachedImport(() => import('#build/dist/server/client.manifest.mjs'))
const getSSRApp = cachedImport(() => import('#build/dist/server/server.mjs'))
const getSSRApp = !process.env.NUXT_NO_SSR && cachedImport(() => import('#build/dist/server/server.mjs'))
const publicPath = (publicConfig.app && publicConfig.app.assetsPath) || process.env.PUBLIC_PATH || '/_nuxt'
@ -33,14 +33,32 @@ const getSPARenderer = cachedResult(async () => {
serverRendered: false,
config: publicConfig
}
let entryFiles = Object.values(clientManifest).filter(
(fileValue: any) => fileValue.isEntry
)
if ('all' in clientManifest && 'initial' in clientManifest) {
// Upgrade legacy manifest (also see normalizeClientManifest in vue-bundle-renderer)
// https://github.com/nuxt-contrib/vue-bundle-renderer/issues/12
entryFiles = clientManifest.initial.map(file => ({ file }))
}
return {
html: '<div id="__nuxt"></div>',
renderResourceHints: () => '',
renderStyles: () => '',
renderScripts: () => clientManifest.initial.map((s) => {
const isMJS = !s.endsWith('.js')
return `<script ${isMJS ? 'type="module"' : ''} src="${publicPath}${s}"></script>`
}).join('')
renderStyles: () =>
entryFiles
.flatMap(({ css }) => css)
.filter(css => css != null)
.map(file => `<link rel="stylesheet" href="${publicPath}${file}">`)
.join(''),
renderScripts: () =>
entryFiles
.map(({ file }) => {
const isMJS = !file.endsWith('.js')
return `<script ${isMJS ? 'type="module"' : ''} src="${publicPath}${file}"></script>`
})
.join('')
}
}
})