From 411ecabd1055606fc3581591e8560a897d22e015 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 11 Sep 2023 09:47:57 +0100 Subject: [PATCH] fix(vite): add css to manifest without `cssCodeSplit` (#23049) --- packages/vite/src/manifest.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/manifest.ts b/packages/vite/src/manifest.ts index b4026fad95..dcd2040aff 100644 --- a/packages/vite/src/manifest.ts +++ b/packages/vite/src/manifest.ts @@ -1,5 +1,5 @@ import fse from 'fs-extra' -import { resolve } from 'pathe' +import { relative, resolve } from 'pathe' import { withTrailingSlash, withoutLeadingSlash } from 'ufo' import escapeRE from 'escape-string-regexp' import { normalizeViteManifest } from 'vue-bundle-renderer' @@ -47,6 +47,15 @@ export async function writeManifest (ctx: ViteBuildContext, css: string[] = []) await fse.mkdirp(serverDist) + if (ctx.config.build?.cssCodeSplit === false) { + const entryCSS = Object.values(clientManifest as Record).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) await ctx.nuxt.callHook('build:manifest', manifest)