fix(frontend): inline only the package version, not the whole package.json (#11191)

`vite.config.js` had `define: { __pkg__: version }` where `version` was
the entire parsed `package.json`. Vite's `define` substitutes the full
object literal at every site that reads `__pkg__.version`, so each of
those sites became `{name:..., version:..., scripts:{...},
devDependencies:{...}, ...}.version` in the client bundle and the
minifier kept the object. On origin/main that is 11 copies of a
22,093-byte object (npm scripts, dependency/devDependency lists,
overrides) across three chunks — 243,023 bytes of package.json shipped
to every browser, for a single version string.

The only property ever read is `__pkg__.version` (script_helpers.ts,
apps/editor/component/default-codes.ts, flows/content/s3Scripts/deno.ts),
and the declarations in src/app.d.ts, src/global.d.ts and
sharedUtils/sharedUtils.d.ts already type it as `{ version: string }`,
so define the dotted expression `__pkg__.version` to the JSON-encoded
version string instead. Any new property read would now fail
`npm run check` rather than silently compile to `undefined`.

Verification (npm ci, generate-backend-client, check, build):
- `npm run check`: 0 errors, 82 warnings.
- `grep -l '"generate-backend-client"' build/_app/immutable/**/*.js`:
  3 chunks before, none after.
- `grep -c 'windmill-labs/components' -r build/_app/immutable`: 11 → 0.
- `npm:windmill-client@1.813.0` still appears in the chunks that build
  the default Deno/pgsql/S3 snippets (3 chunks, 11 sites).
- build/_app/immutable apparent size: 81,815 KB → 81,578 KB
  (JS bytes 54,202,793 → 53,959,705, -243,088 bytes).

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Alexander Petric
2026-09-18 14:34:11 +02:00
committed by GitHub
co-authored by Claude Fable 5.1
parent ecd0a6c77b
commit 813e486e16
+5 -2
View File
@@ -6,7 +6,10 @@ import mkcert from 'vite-plugin-mkcert'
const file = fileURLToPath(new URL('package.json', import.meta.url))
const json = readFileSync(file, 'utf8')
const version = JSON.parse(json)
// Only the version is exposed to the client (see `define` below). Defining the
// whole parsed package.json would inline it — scripts, dependency lists, ... —
// into every chunk that reads `__pkg__.version`.
const { version } = JSON.parse(json)
// The postinstall downloads the pinned UI Builder artifact into static/ui_builder,
// which SvelteKit serves at /ui_builder. Serve that directly; only proxy to a
@@ -278,7 +281,7 @@ const config = {
assertAcyclicChunks(),
assertLeanPublicAppRoutes()
],
define: { __pkg__: version },
define: { '__pkg__.version': JSON.stringify(version) },
optimizeDeps: {
include: ['highlight.js', 'highlight.js/lib/core', 'monaco-vim'],
exclude: [