# `Volt.Assets`
[🔗](https://github.com/elixir-volt/volt/blob/v0.16.0/lib/volt/assets.ex#L1)

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 when small enough
    import icon from './icon.svg'
    // icon = "data:image/svg+xml;base64,..."

    // Forced public URL
    import photo from './photo.jpg?url'
    // photo = "/assets/photo-a1b2c3d4.jpg"

    // Raw file contents
    import text from './message.txt?raw'

JavaScript `new URL("./asset.ext", import.meta.url)` references and CSS
`url("./asset.ext")` references are also routed through this asset pipeline in
production builds.

# `asset?`

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

Check if a path is a known asset type.

# `copy_hashed`

```elixir
@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}`.

# `emit_js_module`

```elixir
@spec emit_js_module(
  String.t(),
  keyword()
) :: {:ok, %{code: String.t(), assets: [String.t() | map()]}} | {:error, term()}
```

Generate a JS module for an asset and return emitted asset metadata.

# `manifest_asset`

```elixir
@spec manifest_asset(String.t(), String.t(), keyword()) :: map()
```

Build manifest metadata for an emitted asset.

# `mime_type`

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

Get MIME type for a file extension.

# `resolve`

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

Resolve an asset-like specifier to an existing source file path.

This is the filesystem side of Volt's Vite-like asset semantics. It resolves
aliases, relative specifiers, root-relative specifiers, and plain asset-root
paths without pulling in build graph concerns such as externals or package
imports.

## Options

  * `:root` — asset root for `/logo.svg` and `"logo.svg"` specifiers
  * `:importer` — source file used as the base for relative specifiers
  * `:aliases` — Volt alias map, typically from `Volt.Config.build().aliases`
  * `:extensions` — extensions to try when the specifier has none

# `resolve!`

```elixir
@spec resolve!(
  String.t(),
  keyword()
) :: String.t()
```

Resolve an asset-like specifier or raise `ArgumentError`.

# `to_js_module`

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

Generate a JS module that exports asset content or a URL.

## Options

  * `:raw` — export the file contents as a string
  * `:url` — force a public URL instead of inlining
  * `:inline` — force a data URI
  * `:no_inline` — force a public URL even for small assets
  * `:inline_limit` — byte threshold for default inlining (default: 4096)
  * `:prefix` — URL prefix for referenced assets (default: `"/assets"`)
  * `:outdir` — output directory for copied assets (production only)
  * `:url_path` — dev-server URL to export when no `:outdir` is provided

---

*Consult [api-reference.md](api-reference.md) for complete listing*
