Repository navigation
Description
Summary
The pre-built UI bundle that ships inside @teambit/ui (artifacts/ui-bundle/) is ~90 MB. It is
built twice — once per UI root (workspace and scope) — and the scope copy additionally carries a
45 MB SSR build. There is a lot of room to shrink this.
This matters more than it used to: the esbuild CLI-bundling work relies on shipping this artifact so
bit start can serve a pre-built UI instead of running rspack at startup. At that point the artifact
is a large fraction of the whole distribution (~90 MB of a ~320 MB bundled bit), and the single
biggest remaining size lever.
Measurements
Measured on bit-bundle3, artifact produced by the BundleUI build task:
| part | size | files |
|---|---|---|
ui-bundle/workspace (browser) |
22.6 MB | 39 |
ui-bundle/scope (browser) |
22.6 MB | 54 |
ui-bundle/scope/public/bit/ssr |
45.2 MB | 45 |
| total | 90.4 MB | 138 |
For comparison, the released 2.0.72 artifact is 58 MB (50 MB scope + 8.2 MB workspace), so this
has also grown — worth understanding separately.
Largest single file: scope/public/bit/ssr/index.js at 38 MB.
Two observations
1. workspace and scope are two full builds of the same app
Both are 22.6 MB browser bundles of the same Bit UI, differing only in the root aspect
(teambit.workspace/workspace vs teambit.scope/scope). BundleUiTask simply loops over both roots
and runs UiMain.build for each:
Object.values(UIROOT_ASPECT_IDS).map(async (uiRootAspectId) => {
const outputPath = join(capsule.path, BundleUiTask.getArtifactDirectory(uiRootAspectId));
await this.ui.build(uiRootAspectId, outputPath);
await this.generateHash(outputPath);
})Only 25 files / 1.9 MB are byte-identical between them, so naive file-level dedup buys little —
the two builds chunk and content-hash independently even where the underlying modules are the same.
The duplication is logical rather than byte-level: React, the component-compare UI, monaco, the
graph/tree components etc. are compiled into both.
Possible directions:
- one rspack build with two entry points, sharing chunks via
splitChunks, so the common vendor and
UI chunks are emitted once; - or a shared runtime/vendor chunk emitted to a common dir that both roots reference.
2. The 45 MB SSR build is only ever used by the scope root
setupServerSideRendering returns immediately unless buildOptions.ssr:
private async setupServerSideRendering({ root, port, app }) {
if (!this.buildOptions?.ssr) return;
...
}ssr: true is set only on scope.ui-root.ts; workspace.ui-root.ts has ssr: false. So half the
artifact serves one root, and is never touched by bit start in a workspace — which is the common
case, and the only case a bundled CLI needs by default.
Worth asking:
- is SSR still required for the scope UI? If yes, can it be a separate optional artifact rather than
part of the package every install pulls down? - 38 MB for a single
ssr/index.jslooks high on its own and may be worth ametafileinspection
independently of the packaging question.
Reproduce
bit build "teambit.ui-foundation/ui" --tasks "BundleUI" --reuse-capsules --unmodified
# then, in the capsule printed as "build output can be found in path:"
du -sh teambit.ui-foundation_ui@*/artifacts/ui-bundle/{workspace,scope}
du -sh teambit.ui-foundation_ui@*/artifacts/ui-bundle/scope/public/bit/ssrRelated
Context on why the artifact is now shipped inside the CLI bundle, and the numbers above, are recorded
in bundle-plan.md §17 on the bit-bundle3 branch.
Activity
docs(bundle): record how `bit start` was made to work from the pre-bu…
zkochan commentedon Aug 13, 2026
Two things from #10612 that bear on the first direction here (one build, two entries, shared
chunks), one supporting it and one that is the actual work.
The duplication costs memory, not just artifact size.
bit buildruns every task in oneprocess, and until #10612 neither rspack compiler was ever closed, so both UI module graphs — plus
rspack's native side of them — stayed resident through every task that followed, including a preview
bundle per env. On #10465 that process was being OOM-killed during those preview bundles. #10612
releases the graphs once
BundleUIis done, which helps after the task, but the peak during it isstill two complete compilations of the same app. One build with shared chunks lowers that peak
rather than cleaning up behind it, so the size win and the memory win are the same change.
It would also delete machinery. Because the two roots bundle concurrently, #10612 had to defer the
close to the end of the task (
openBuildCompilers+ adeferCloseoption onUiMain.build) insteadof closing inside
build(). With a single compiler that question disappears and it collapses intoone close in
build()'sfinally.The snag is the artifact layout, not the rspack config. Everything downstream is per-root by
construction:
BundleUiTask.getArtifactDirectory(uiRootAspectId)maps each root aspect id toartifacts/ui-bundle/{scope,workspace};getArtifactDef()declares two artifacts, each globbing one of those directories;generateHash()writes a.hashper root directory.A single compilation has one
output.path, so shared chunks need a third location that both roots'HTML references, and then: what do the two artifact defs contain, does a shared chunk dir belong to
both or to neither, and what does
.hashmean once the roots are no longer independent (it is readto decide whether the pre-built bundle is current). That is the second bullet in the issue — the
shared vendor/runtime dir — and it is where the design decision actually sits.
Since SSR is scope-only and is created by the same
UiMain.buildcall (buildOptions.ssr), the samelayout decision covers observation 2: whatever mechanism lets an artifact be optional/separate would
apply to the 45 MB SSR output too.
fix(ui, preview): release the bundle compilers, and transpile TypeScr…
fix(ui): repair scope SSR and shrink the ui pre-bundle 58MB to 24MB (#…
perf(ui): bundle both ui roots in one compilation, 24MB to 16MB (#10629)
test(ui): bit start sanity e2e, plus fixes for the qodo findings on #…