PhoenixAssets. Manifest
(PhoenixAssets v0.1.0)
View Source
Parses and queries a Vite build manifest.
Vite writes a manifest.json keyed by source path; each entry records its
hashed output file, its css, and the chunk imports it depends on (by
manifest key). This module resolves those relationships -- recursively
following imports and de-duplicating -- so a caller can ask "for this entry,
what stylesheet links, script src, and module preloads do I emit?".
Root-relative paths are prefixed with / (Vite emits them relative to the
served static root); absolute http(s):// URLs -- an entry Vite resolves to a
CDN origin -- pass through unchanged.
The query functions (file/2, css/2, imports/2, subresource_integrity/2)
all raise KeyError when the requested top-level key is absent; transitive
imports missing from the manifest are skipped.
Summary
Functions
All stylesheet hrefs for key, including those of its transitive imports.
Fetches the raw chunk for key, raising KeyError if it is absent.
The hashed output file for key (prefixed with /).
Transitively imported chunk files for key, excluding its own file.
Loads and decodes a Vite manifest from path.
Module preload targets for key (its transitively imported chunk files).
Subresource-integrity hashes for key, keyed by served href.
Types
Functions
All stylesheet hrefs for key, including those of its transitive imports.
Raises KeyError when key itself is absent (like file/2 and
imports/2); transitive imports that are missing from the manifest are
skipped.
iex> manifest = %{"src/app.ts" => %{"file" => "assets/app.js", "css" => ["assets/app.css"]}}
iex> PhoenixAssets.Manifest.css(manifest, "src/app.ts")
["/assets/app.css"]
Fetches the raw chunk for key, raising KeyError if it is absent.
A missing key also emits [:phoenix_assets, :manifest, :missing_entry], so
production observability catches requests for entries the build no longer
produces.
The hashed output file for key (prefixed with /).
iex> manifest = %{"src/app.ts" => %{"file" => "assets/app-Cw3Qz1.js"}}
iex> PhoenixAssets.Manifest.file(manifest, "src/app.ts")
"/assets/app-Cw3Qz1.js"
Transitively imported chunk files for key, excluding its own file.
Loads and decodes a Vite manifest from path.
Module preload targets for key (its transitively imported chunk files).
Subresource-integrity hashes for key, keyed by served href.
Returns a map of href => integrity for the entry's own file and its
transitively imported chunk files, for every chunk that carries an integrity
field. Vite emits that field only when an SRI plugin is configured, so the map
is empty otherwise -- callers render integrity/crossorigin only when a hash
is present.
Raises KeyError when key itself is absent (like file/2, css/2, and
imports/2).
iex> manifest = %{"src/app.ts" => %{"file" => "assets/app.js", "integrity" => "sha384-abc"}}
iex> PhoenixAssets.Manifest.subresource_integrity(manifest, "src/app.ts")
%{"/assets/app.js" => "sha384-abc"}