Skip to content

Commit 3ee377b

Browse files
committed
feat: calculate chunk size
1 parent af536fd commit 3ee377b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

packages/vite/src/app/components/data/ChunkDetails.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang="ts">
22
import type { Chunk as ChunkInfo } from '@rolldown/debug'
33
import type { SessionContext } from '~~/shared/types'
4+
import { computed } from 'vue'
45
5-
withDefaults(defineProps<{
6+
const props = withDefaults(defineProps<{
67
chunk: ChunkInfo
78
session: SessionContext
89
showModules?: boolean
@@ -11,6 +12,20 @@ withDefaults(defineProps<{
1112
showModules: true,
1213
showImports: true,
1314
})
15+
16+
const modulesMap = computed(() => {
17+
const map = new Map()
18+
for (const module of props.session.modulesList) {
19+
map.set(module.id, module)
20+
}
21+
return map
22+
})
23+
24+
const chunkSize = computed(() => props.chunk.modules.reduce((total, moduleId) => {
25+
const moduleInfo = modulesMap.value.get(moduleId)
26+
const transforms = moduleInfo?.buildMetrics?.transforms
27+
return transforms?.length ? total + transforms[transforms.length - 1]!.transformed_code_size : total
28+
}, 0))
1429
</script>
1530

1631
<template>
@@ -20,7 +35,7 @@ withDefaults(defineProps<{
2035
<div i-ph-shapes-duotone />
2136
<div>{{ chunk.name || '[unnamed]' }}</div>
2237
<DisplayBadge :text="chunk.reason" />
23-
<!-- TODO: Estimated Chunk Size -->
38+
<DisplayFileSizeBadge :bytes="chunkSize" text-sm />
2439
</div>
2540

2641
<div flex-auto />

0 commit comments

Comments
 (0)