Noizu.Tessera.Hologram.Standalone (Noizu.Tessera v0.2.0)

Copy Markdown View Source

Tier 2 spike: compiles ORDINARY Hologram components into standalone, host-agnostic bundles by driving Hologram's own compiler pipeline.

Approach (item 1 of the spike brief — "synthetic stub page"):

  • a throwaway stub page + layout per target component is generated, compiled to BEAM in a scratch dir and loaded into the VM,
  • the exact pipeline of Mix.Tasks.Compile.Hologram is replayed against ONLY those stub pages — build_ir_plt → build_call_graph → list_async_mfas → clone + remove_manually_ported_mfas → list_runtime_mfas → remove_runtime_mfas! → build_page_js / build_runtime_js,
  • the emitted page JS gets string surgery: the globalThis.Hologram.pageReachableFunctionDefs = (deps) => {...} assignment becomes a plain const tesseraDefs = (deps) => {...} + export default, and the pageScriptLoaded dispatch tail is stripped — so a component bundle NEVER touches the page-global globalThis.Hologram object a host page may already own.

Internals dependence (documented deliberately)

Everything used is PUBLIC API of the 0.10.1 hex package (Hologram.Compiler.*, Hologram.Compiler.CallGraph.*), but it is pre-1.0 public API, and the string surgery anchors on the exact emitted statements:

  • import PerformanceTimer from ... / const startTime = ... header lines
  • globalThis.Hologram.pageReachableFunctionDefs = (deps) => { (page entry)
  • globalThis.Hologram.pageScriptLoaded = true; (page entry tail)
  • document.addEventListener("hologram:pageScriptLoaded", ...) (runtime entry tail)
  • static #defineManuallyPortedFunctions() { (body extracted verbatim from assets/js/hologram.mjs so the ~33 manual registrations stay in sync with upstream instead of being duplicated here)

Any of those drifting makes the compile fail loudly (anchored splits raise) rather than silently producing broken bundles.

Summary

Functions

Compiles the tessera runtime + one bundle set per given component module.

Functions

compile(components, opts \\ [])

@spec compile([module() | String.t()], keyword()) :: map()

Compiles the tessera runtime + one bundle set per given component module.

Options:

  • :out — output dir (default: priv/static/tessera-holo under cwd)

Writes into out:

  • tessera-runtime.esm.js / tessera-runtime.umd.js — the shared runtime (Hologram client runtime exactly once + tessera shim)
  • <base>.esm.js / <base>.umd.js per component — only that component's compiled Elixir + a runtime-free registrar
  • <base>.standalone.esm.js — runtime + component in one file
  • manifest.json — hologram version, prop contracts, file sizes