Skip to content

Commit 59d0b35

Browse files
authored
perf(css): avoid constructing renderedModules (#19775)
1 parent 175a839 commit 59d0b35

File tree

1 file changed

+13
-4
lines changed
  • packages/vite/src/node/plugins

1 file changed

+13
-4
lines changed

packages/vite/src/node/plugins/css.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,19 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
640640

641641
async renderChunk(code, chunk, opts, meta) {
642642
let chunkCSS = ''
643-
const renderedModules = Object.fromEntries(
644-
Object.values(meta.chunks).flatMap((chunk) =>
645-
Object.entries(chunk.modules),
646-
),
643+
const renderedModules = new Proxy(
644+
{} as Record<string, RenderedModule | undefined>,
645+
{
646+
get(_target, p) {
647+
for (const name in meta.chunks) {
648+
const modules = meta.chunks[name].modules
649+
const module = modules[p as string]
650+
if (module) {
651+
return module
652+
}
653+
}
654+
},
655+
},
647656
)
648657
// the chunk is empty if it's a dynamic entry chunk that only contains a CSS import
649658
const isJsChunkEmpty = code === '' && !chunk.isEntry

0 commit comments

Comments
 (0)