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 =