fix(vite): write dev manifest when ssr: false (#28488)

This commit is contained in:
Daniel Roe 2024-08-09 17:43:42 +01:00 committed by GitHub
parent fb2d7b94cd
commit 4eef63469b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View File

@ -8,12 +8,29 @@ import { normalizeViteManifest } from 'vue-bundle-renderer'
import type { ViteBuildContext } from './vite' import type { ViteBuildContext } from './vite'
export async function writeManifest (ctx: ViteBuildContext) { export async function writeManifest (ctx: ViteBuildContext) {
// This is only used for ssr: false - when ssr is enabled we use vite-node runtime manifest
const devClientManifest = {
'@vite/client': {
isEntry: true,
file: '@vite/client',
css: [],
module: true,
resourceType: 'script',
},
[ctx.entry]: {
isEntry: true,
file: ctx.entry,
module: true,
resourceType: 'script',
},
}
// Write client manifest for use in vue-bundle-renderer // Write client manifest for use in vue-bundle-renderer
const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client') const clientDist = resolve(ctx.nuxt.options.buildDir, 'dist/client')
const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server') const serverDist = resolve(ctx.nuxt.options.buildDir, 'dist/server')
const manifestFile = resolve(clientDist, 'manifest.json') const manifestFile = resolve(clientDist, 'manifest.json')
const clientManifest = JSON.parse(readFileSync(manifestFile, 'utf-8')) const clientManifest = ctx.nuxt.options.dev ? devClientManifest : JSON.parse(readFileSync(manifestFile, 'utf-8'))
const buildAssetsDir = withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir)) const buildAssetsDir = withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir))
const BASE_RE = new RegExp(`^${escapeRE(buildAssetsDir)}`) const BASE_RE = new RegExp(`^${escapeRE(buildAssetsDir)}`)

View File

@ -148,6 +148,7 @@ export async function buildServer (ctx: ViteBuildContext) {
} }
if (!ctx.nuxt.options.ssr) { if (!ctx.nuxt.options.ssr) {
await writeManifest(ctx)
await onBuild() await onBuild()
return return
} }