From 9cc808e94b28e7d9c86b5dcd10f9ae068e5ca6d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 18 Oct 2022 00:45:55 +0900 Subject: [PATCH] fix(legacy): restore entry chunk CSS inlining, reverts #9761 (#10496) --- 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 =