Volt.JS.Vendor (Volt v0.9.0)

Copy Markdown View Source

Pre-bundle vendor (node_modules) dependencies for dev mode.

Scans source files with OXC.imports/2, identifies bare specifiers (non-relative, non-URL), resolves them through node_modules, and bundles each into a single ESM file with OXC.bundle/2.

CJS packages (e.g. React) are automatically converted to ESM during bundling. process.env.NODE_ENV is replaced with "development" so conditional CJS branches resolve correctly.

Bundled files are cached on disk in _build/volt/vendor/.

Summary

Functions

Bundle a single vendor specifier on demand.

Decode a URL-safe specifier back to its original form.

Encode a specifier for use in URLs (escaping @ and /).

Scan source files and pre-bundle any bare npm imports.

Read a pre-bundled vendor file by specifier.

Get the URL path for a vendor module.

Functions

bundle_on_demand(specifier, node_modules, plugins \\ [])

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

Bundle a single vendor specifier on demand.

Used by the dev server when a /@vendor/ request arrives for a specifier that wasn't caught by prebundle/1 (e.g. transitive dependency, or newly added import).

decode_specifier(encoded)

Decode a URL-safe specifier back to its original form.

encode_specifier(specifier)

Encode a specifier for use in URLs (escaping @ and /).

prebundle(opts)

@spec prebundle(keyword()) ::
  {:ok, %{required(String.t()) => String.t()}} | {:error, term()}

Scan source files and pre-bundle any bare npm imports.

Returns a map of specifier → vendor_path for import rewriting.

Options

  • :root — source directory to scan
  • :node_modules — path to node_modules (default: auto-detect)
  • :force — rebuild even if cached (default: false)

read(specifier)

@spec read(String.t()) :: {:ok, String.t()} | {:error, :not_found}

Read a pre-bundled vendor file by specifier.

vendor_url(specifier)

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

Get the URL path for a vendor module.