fix(vite): add css to manifest without cssCodeSplit (#23049)

This commit is contained in:
Daniel Roe 2023-09-11 09:47:57 +01:00 committed by GitHub
parent aa73cbeaf9
commit 411ecabd10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import fse from 'fs-extra' import fse from 'fs-extra'
import { resolve } from 'pathe' import { relative, resolve } from 'pathe'
import { withTrailingSlash, withoutLeadingSlash } from 'ufo' import { withTrailingSlash, withoutLeadingSlash } from 'ufo'
import escapeRE from 'escape-string-regexp' import escapeRE from 'escape-string-regexp'
import { normalizeViteManifest } from 'vue-bundle-renderer' import { normalizeViteManifest } from 'vue-bundle-renderer'
@ -47,6 +47,15 @@ export async function writeManifest (ctx: ViteBuildContext, css: string[] = [])
await fse.mkdirp(serverDist) await fse.mkdirp(serverDist)
if (ctx.config.build?.cssCodeSplit === false) {
const entryCSS = Object.values(clientManifest as Record<string, { file?: string }>).find(val => (val).file?.endsWith('.css'))?.file
if (entryCSS) {
const key = relative(ctx.config.root!, ctx.entry)
clientManifest[key].css ||= []
clientManifest[key].css!.push(entryCSS)
}
}
const manifest = normalizeViteManifest(clientManifest) const manifest = normalizeViteManifest(clientManifest)
await ctx.nuxt.callHook('build:manifest', manifest) await ctx.nuxt.callHook('build:manifest', manifest)