PhoenixMountable.Assets.Static (PhoenixMountable v0.2.1)

Copy Markdown View Source

A directory of built files served under the mount.

For libraries whose frontend is built with Vite, esbuild or another bundler into many files: code-split chunks, fonts, images, a React or Vue app.

# esbuild or plain files
assets: {PhoenixMountable.Assets.Static,
         from: "priv/static/my_lib",
         entries: [css: "app.css", js: "app.js"]}

# Vite, with hashed file names from its manifest
assets: {PhoenixMountable.Assets.Static,
         from: "priv/static/my_lib",
         manifest: ".vite/manifest.json",
         entries: [app: {"src/main.tsx", :module}]}

Options

  • :from — the directory, relative to the library root and inside its priv directory, or {app, path}. Resolved with Application.app_dir/2 at runtime, so it works in releases.
  • :at — the path under the mount. Defaults to "/assets".
  • :manifest — a Vite manifest, relative to :from. Entries are then manifest keys, and their CSS files are added as entries too.
  • :entries — the files a page loads: a name and a file (or manifest key), or {file, kind} with kind :css, :js or :module.

The manifest and the entry files are read at compile time, so the library must be built before it compiles (as it is in a Hex package). Without a manifest, entry URLs carry ?vsn=<md5>; with one, file names are already hashed. Both are cached as immutable.