perf(build): minify dist-experimental esbuild bundle (closes #117)#119
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
minify: true+keepNames: truein the esbuild config that producesdist-experimental/index.js.dist-experimental/index.js: 1395K → 683K (–60%).dist-experimental/total: 2.7M → 1.79M, comfortably under the 3M cap.patchHostDefault()regex so it survives identifier mangling — both legacydist/(env=env) and the new minifieddist-experimental/(env=Ue) get patched correctly.Why
Issue #117 (
area:tarball): the experimental bundle ships unminified, paying a ~700K size penalty in everynpx @forgeplan/web init --experimentalinstall. PRD-014 SC-1 already pins a ≤3M cap ondist/; minifying brings the experimental shape closer to a future graduation target with headroom for upgrades.Notes on choices:
keepNames: true— preservesFunction.name/class.nameso sirv, polka, and SvelteKit error formatters that key off names still resolve.legalComments: "none"was already set, so no license-banner regression.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 buildsucceeds, bothdist/anddist-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 smokepasses (legacydist/happy path).--experimental, start server, probe endpoints —/api/healthok,/api/listok,GET /returns HTML, all 200.dirSizeBytes(DIST_EXPERIMENTAL)= 1.88M, well belowDIST_EXPERIMENTAL_MAX_BYTES = 3Mcap.Refs: PRD-014, #117
🤖 Generated with Claude Code