From 7efdb486dbe65382b6293e28c70ab6348bb4a874 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 27 Jun 2022 20:08:52 +0800 Subject: [PATCH] fix(vite-node): on-demand manifest (#5017) --- .../nuxt/src/core/runtime/nitro/renderer.ts | 21 +++++++++++++------ packages/vite/src/runtime/client.manifest.mjs | 4 +--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 98cfba67fc..085e5564c2 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -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 `
${html}
` - } - 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 `
${html}
` + } + + return renderer }) // -- SPA Renderer -- diff --git a/packages/vite/src/runtime/client.manifest.mjs b/packages/vite/src/runtime/client.manifest.mjs index f69d7371d2..f33e3b2a79 100644 --- a/packages/vite/src/runtime/client.manifest.mjs +++ b/packages/vite/src/runtime/client.manifest.mjs @@ -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 })