mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 15:15:19 +00:00
fix(vite-node): on-demand manifest (#5017)
This commit is contained in:
parent
026903c5e7
commit
7efdb486db
@ -30,7 +30,9 @@ interface RenderResult {
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const getClientManifest = () => import('#build/dist/server/client.manifest.mjs').then(r => r.default || r)
|
||||
const getClientManifest = () => import('#build/dist/server/client.manifest.mjs')
|
||||
.then(r => r.default || r)
|
||||
.then(r => typeof r === 'function' ? r() : r)
|
||||
|
||||
// @ts-ignore
|
||||
const getServerEntry = () => process.env.NUXT_NO_SSR ? Promise.resolve(null) : import('#build/dist/server/server.mjs').then(r => r.default || r)
|
||||
@ -46,15 +48,22 @@ const getSSRRenderer = lazyCachedFunction(async () => {
|
||||
if (!createSSRApp) { throw new Error('Server bundle is not available') }
|
||||
|
||||
// Create renderer
|
||||
const renderToString = async (input, context) => {
|
||||
const html = await _renderToString(input, context)
|
||||
return `<div id="__nuxt">${html}</div>`
|
||||
}
|
||||
return createRenderer(createSSRApp, {
|
||||
const renderer = createRenderer(createSSRApp, {
|
||||
clientManifest,
|
||||
renderToString,
|
||||
publicPath: buildAssetsURL()
|
||||
})
|
||||
|
||||
async function renderToString (input, context) {
|
||||
const html = await _renderToString(input, context)
|
||||
// In development with vite-node, the manifest is on-demand and will be available after rendering
|
||||
if (process.dev && process.env.NUXT_VITE_NODE_OPTIONS) {
|
||||
renderer.rendererContext.updateManifest(await getClientManifest())
|
||||
}
|
||||
return `<div id="__nuxt">${html}</div>`
|
||||
}
|
||||
|
||||
return renderer
|
||||
})
|
||||
|
||||
// -- SPA Renderer --
|
||||
|
@ -3,6 +3,4 @@ import { getViteNodeOptions } from './vite-node-shared.mjs'
|
||||
|
||||
const viteNodeOptions = getViteNodeOptions()
|
||||
|
||||
const manifest = await $fetch('/manifest', { baseURL: viteNodeOptions.baseURL })
|
||||
|
||||
export default manifest
|
||||
export default () => $fetch('/manifest', { baseURL: viteNodeOptions.baseURL })
|
||||
|
Loading…
Reference in New Issue
Block a user