From 49886dde2c74072ae2a424dba62fc17b680d6bd5 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 17 Oct 2022 17:22:00 +0900 Subject: [PATCH] fix(legacy): restore entry chunk CSS inlining, revert #9761 --- packages/vite/src/node/plugins/css.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 824dc8d571c91e..dad328164d476b 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -566,12 +566,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } else if (!config.build.ssr) { // legacy build and inline css - // the legacy build should avoid inserting entry CSS modules here, they - // will be collected into `chunk.viteMetadata.importedCss` and injected - // later by the `'vite:build-html'` plugin into the `index.html` - if (chunk.isEntry && !config.build.lib) { - return null - } + // Entry chunk CSS will be collected into `chunk.viteMetadata.importedCss` + // and injected later by the `'vite:build-html'` plugin into the `index.html` + // so it will be duplicated. (https://github.com/vitejs/vite/issues/2062#issuecomment-782388010) + // But because entry chunk can be imported by dynamic import, + // we shouldn't remove the inlined CSS. (#10285) + chunkCSS = await finalizeCss(chunkCSS, true, config) let cssString = JSON.stringify(chunkCSS) cssString =