Skip to content

perf(build): minify dist-experimental esbuild bundle (closes #117)#119

Merged
fedorovvvv merged 1 commit into
developfrom
feature/issue-117-minify-bundle
May 9, 2026
Merged

perf(build): minify dist-experimental esbuild bundle (closes #117)#119
fedorovvvv merged 1 commit into
developfrom
feature/issue-117-minify-bundle

Conversation

@fedorovvvv
Copy link
Copy Markdown
Collaborator

Summary

  • Enable minify: true + keepNames: true in the esbuild config that produces dist-experimental/index.js.
  • dist-experimental/index.js: 1395K → 683K (–60%).
  • dist-experimental/ total: 2.7M → 1.79M, comfortably under the 3M cap.
  • Loosen the patchHostDefault() regex so it survives identifier mangling — both legacy dist/ (env=env) and the new minified dist-experimental/ (env=Ue) get patched correctly.

Why

Issue #117 (area:tarball): the experimental bundle ships unminified, paying a ~700K size penalty in every npx @forgeplan/web init --experimental install. PRD-014 SC-1 already pins a ≤3M cap on dist/; minifying brings the experimental shape closer to a future graduation target with headroom for upgrades.

Notes on choices:

  • keepNames: true — preserves Function.name / class.name so sirv, polka, and SvelteKit error formatters that key off names still resolve.
  • legalComments: "none" was already set, so no license-banner regression.
  • The 3M cap (DIST_EXPERIMENTAL_MAX_BYTES) is left as-is — 1.79M actual leaves 40% headroom for legitimate growth (Svelte/d3/adapter-node bumps).

Test plan

  • npm run build succeeds, both dist/ and dist-experimental/ produced.
  • [build] patched HOST default 0.0.0.0 → 127.0.0.1 in ./dist/index.js (env=env) — legacy still patches.
  • [build] patched HOST default 0.0.0.0 → 127.0.0.1 in ./dist-experimental/index.js (env=Ue) — minified bundle gets the loopback patch with the mangled identifier captured.
  • npm run smoke passes (legacy dist/ happy path).
  • Experimental shim smoke (manual): init --experimental, start server, probe endpoints — /api/health ok, /api/list ok, GET / returns HTML, all 200.
  • dirSizeBytes(DIST_EXPERIMENTAL) = 1.88M, well below DIST_EXPERIMENTAL_MAX_BYTES = 3M cap.

Refs: PRD-014, #117

🤖 Generated with Claude Code

Add `minify: true` + `keepNames: true` to the esbuild config in
`bundleExperimentalDist()`. The unminified single-file ESM bundle was
~1.4M; minification drops `dist-experimental/index.js` from 1395K to 683K
(–60%) and the full `dist-experimental/` from 2.7M to 1.79M, well below
the existing 3M cap (PRD-014 SC-1).

Side effect: minification renames the SvelteKit `env('HOST', '0.0.0.0')`
helper to a short identifier (e.g. `Ue(...)`), breaking the literal regex
in `patchHostDefault()`. Loosen the regex to capture whatever identifier
the minifier picked and reuse it in the replacement, so both the legacy
`dist/` (unminified, `env=env`) and the new `dist-experimental/`
(minified, `env=Ue`) get patched correctly. Verified by smoke run: the
experimental bundle binds to 127.0.0.1, `/api/health`, `/api/list`, and
`GET /` all return 200.

`keepNames: true` preserves `Function.name` / `class.name` so any runtime
diagnostics that key off names (sirv, polka, kit error formatters) still
resolve.

Closes #117
Refs: PRD-014

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fedorovvvv fedorovvvv merged commit 131ad07 into develop May 9, 2026
3 checks passed
@fedorovvvv fedorovvvv deleted the feature/issue-117-minify-bundle branch May 9, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant