Behaviour for Volt build plugins.
Plugins can participate in resolution, loading, compilation, import
extraction, and final chunk rendering. All callbacks except name/0 are
optional.
Plugins may be configured as modules or {module, opts} tuples. When a
plugin defines a callback with one extra arity, Volt passes the tuple opts as
the final argument.
Summary
Callbacks
Compile a source file into browser-ready JavaScript plus optional CSS.
Return extensions owned by this plugin for :compile, :resolve, :watch, or :scan.
Extract static/dynamic imports and worker specifiers from a source file.
Load content for a resolved module path.
Plugin name for identification and error messages.
Return the canonical prebundle specifier to use for an import, or pass with nil.
Return a generated prebundle entry for a canonical specifier, or pass with nil.
Transform a final output chunk before writing.
Resolve an import specifier to a file path, :skip, or pass with nil.
Transform compiled JavaScript before serving or bundling.
Types
Callbacks
@callback compile(path :: String.t(), source :: String.t(), opts :: keyword()) :: {:ok, compiled()} | {:error, term()} | nil
Compile a source file into browser-ready JavaScript plus optional CSS.
Return extensions owned by this plugin for :compile, :resolve, :watch, or :scan.
@callback extract_imports(path :: String.t(), source :: String.t(), opts :: keyword()) :: {:ok, %{imports: [{:static | :dynamic, String.t()}], workers: [String.t()]}} | {:error, term()} | nil
Extract static/dynamic imports and worker specifiers from a source file.
Load content for a resolved module path.
@callback name() :: String.t()
Plugin name for identification and error messages.
Return the canonical prebundle specifier to use for an import, or pass with nil.
@callback prebundle_entry(specifier :: String.t()) :: {:source, filename :: String.t(), source :: String.t()} | {:proxy, filename :: String.t(), keyword()} | nil
Return a generated prebundle entry for a canonical specifier, or pass with nil.
Transform a final output chunk before writing.
@callback resolve(specifier :: String.t(), importer :: String.t() | nil) :: {:ok, String.t()} | :skip | nil
Resolve an import specifier to a file path, :skip, or pass with nil.
Transform compiled JavaScript before serving or bundling.