perf(build): drop the JIT compiler from production, 1.55 MB -> 1.04 MB (FH-3.4)

Built with --stats-json and read the esbuild metafile instead of guessing.
@angular/compiler was 495,831 bytes of a 1.5 MB main chunk - the JIT
compiler, in an AOT production build, 33% of everything an anonymous
visitor downloads.

src/main.ts imported it deliberately, with a comment explaining that
@marketplaces/auth shipped plain tsc output carrying no Ivy metadata, so
Angular JIT-compiled its classes at runtime and bootstrap threw without
it.

That comment was stale. The package is 0.2.0, built with ng-packagr,
module: dist/fesm2022/marketplaces-auth.mjs - proper Angular Package
Format, partial-compiled (ɵɵngDeclareInjectable), linked at consumer
build time. Nothing needs JIT.

Verified against the production bundle served statically, not just a
green build: the failure mode this guarded was a runtime throw, so a
successful compile proves nothing. Angular 22.0.8 bootstrapped, the
router resolved /ru, and the app rendered its own "server unavailable"
screen - meaning DI, HttpClient and the full interceptor chain ran. That
chain injects AuthService from @marketplaces/auth, the exact class the
old comment named. Zero JIT or compiler errors; the only console output
was the expected 404s from having no backend behind a static server.

Initial bundle 1.55 MB -> 1.04 MB raw, 323.58 kB -> 215.45 kB transfer.
Budget ratchet lowered 1.6MB -> 1.1MB, which is now also what stops the
import being re-added.

Next lever, deliberately not taken here: i18n/ru.ts is 290 kB, eager,
while en/hy are already lazy. TranslateService has the loader plumbing
and languageGuard already awaits a preload, so it is mechanically small -
but it adds a round-trip before first paint for the majority language,
which is a product tradeoff, not a cleanup. Roughly a 750 kB bundle once
someone decides.

256 tests pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
sdarbinyan
2026-08-21 16:10:34 +04:00
parent a35953d90f
commit 771dce9e29
3 changed files with 40 additions and 20 deletions

View File

@@ -1,15 +1,14 @@
import 'zone.js';
// @marketplaces/auth ships plain tsc output (dist/index.js), not Angular
// Package Format - its classes carry no compiled Ivy DI metadata, so Angular
// falls back to JIT-compiling them at runtime. Without this import that
// throws immediately on first injection (AuthService, Ed25519 services, any
// class from the package), which breaks app bootstrap and admin auth
// entirely. Real fix: publish the package via ng-packagr. Tracked - do not
// remove this import until that ships.
// No '@angular/compiler' import here, deliberately. It was needed while
// @marketplaces/auth shipped plain tsc output with no Ivy metadata, forcing
// Angular to JIT-compile the package's classes at runtime. The package is
// published via ng-packagr as of 0.2.0 - partial-compiled, linked at build
// time - so the JIT compiler is dead weight: 496 kB of a 1.5 MB initial
// bundle. Re-adding it will blow the bundle budget in CI, which is the
// intended guard.
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { App } from './app/app';
import '@angular/compiler';
bootstrapApplication(App, appConfig)
.catch((err) => console.error(err));