From 28f938f2c8fb72e3d766ea6aeb15e70c343109a8 Mon Sep 17 00:00:00 2001 From: yoho Date: Fri, 19 Aug 2022 22:47:28 +0800 Subject: [PATCH 1/2] perf: legacy avoid insert the entry module css --- packages/vite/src/node/plugins/css.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index c8c454d2f1a267..1e1d08798911a5 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -557,6 +557,14 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }) chunk.viteMetadata.importedCss.add(this.getFileName(fileHandle)) } else if (!config.build.ssr) { + // legacy build and inline css + + // simple build will collect all entry module css into chunk.viteMetadata.importedCss + // and inject into the `index.html` same with legacy + // legacy build should avoid insert the entry module css again + if (chunk.isEntry) { + return null + } chunkCSS = await finalizeCss(chunkCSS, true, config) let cssString = JSON.stringify(chunkCSS) cssString = From fc40b7fda30a64c886b810260eb9da914ff60491 Mon Sep 17 00:00:00 2001 From: patak Date: Fri, 19 Aug 2022 17:07:21 +0200 Subject: [PATCH 2/2] chore: update comment --- packages/vite/src/node/plugins/css.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 1e1d08798911a5..4dc3aa7f158587 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -559,9 +559,9 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { } else if (!config.build.ssr) { // legacy build and inline css - // simple build will collect all entry module css into chunk.viteMetadata.importedCss - // and inject into the `index.html` same with legacy - // legacy build should avoid insert the entry module css again + // 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) { return null }