Volt.Assets (Volt v0.10.1)

Copy Markdown View Source

Static asset handling — images, fonts, SVGs, and other non-code files.

Small assets (below the inline threshold) are inlined as base64 data URIs. Larger assets are copied with content-hashed filenames.

Import patterns

// Inlined as data URI (small file)
import icon from './icon.svg'
// icon = "data:image/svg+xml;base64,..."

// Hashed URL (large file)
import photo from './photo.jpg'
// photo = "/assets/photo-a1b2c3d4.jpg"

Summary

Functions

Check if a path is a known asset type.

Copy an asset to the output directory with a content-hashed filename.

Get MIME type for a file extension.

Generate a JS module that exports the asset URL or data URI.

Functions

asset?(path)

@spec asset?(String.t()) :: boolean()

Check if a path is a known asset type.

copy_hashed(source_path, outdir)

@spec copy_hashed(String.t(), String.t()) :: {:ok, String.t()}

Copy an asset to the output directory with a content-hashed filename.

Returns {:ok, hashed_filename}.

mime_type(path)

@spec mime_type(String.t()) :: String.t()

Get MIME type for a file extension.

to_js_module(path, opts \\ [])

@spec to_js_module(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Generate a JS module that exports the asset URL or data URI.

Options

  • :inline_limit — byte threshold for inlining (default: 4096)
  • :prefix — URL prefix for hashed assets (default: "/assets")
  • :outdir — output directory for copied assets (production only)