From e97748437cc1f32fc06a2711cecf24bb9bacafd1 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Wed, 6 May 2026 16:11:32 -0500 Subject: [PATCH] build(assets): split coverage hooks into a lazy-loaded chunk Switch esbuild to ESM with --splitting and load app.js as type=module. Heavy hooks now ship in their own chunk and only download when their LiveView mounts. - assets/js/lib/leaflet.ts: extract ensureLeaflet (vendored Leaflet loader) into a shared module with a typed window.L declaration. - assets/js/hooks/coverage_hooks.ts: extract CoverageMap, MultiCoverageMap, and CoverageLocationPicker (~510 lines) with proper interface types for hook context and tightened typing on payloads / event handlers (CoveragePayload is now a real type). - app.ts: replace those three inline hook bodies with lazyHook stubs that call import('./hooks/coverage_hooks') on first mount, forwarding lifecycle hooks once the chunk resolves. Also adds a scoped `declare const L: any` so the remaining Leaflet hooks type-check. - root.html.heex: switch the script tag to type=module so the emitted ESM bundle can use dynamic import(). - esbuild config: add --splitting --format=esm. Build output now produces: app.js 1.2 MB coverage_hooks-.js 16 KB (lazy) chunk-.js 2.4 KB (shared, lazy) --- assets/js/app.ts | 583 +----------------- assets/js/hooks/coverage_hooks.ts | 541 ++++++++++++++++ assets/js/lib/leaflet.ts | 49 ++ config/config.exs | 4 +- .../components/layouts/root.html.heex | 2 +- 5 files changed, 626 insertions(+), 553 deletions(-) create mode 100644 assets/js/hooks/coverage_hooks.ts create mode 100644 assets/js/lib/leaflet.ts diff --git a/assets/js/app.ts b/assets/js/app.ts index 62c804bf..96a0f660 100644 --- a/assets/js/app.ts +++ b/assets/js/app.ts @@ -1643,46 +1643,35 @@ const LeafletMap = { } } -// Lazy-loads the vendored Leaflet bundle (priv/static/vendor/leaflet/) -// the first time any Leaflet hook mounts. Per AGENTS.md we can't put -// inline