Vize.SFC (Vize v0.14.2)

Copy Markdown View Source

Bundler-oriented helpers for Vue Single File Components.

These helpers expose Vize's SFC dependency and scope-ID logic without requiring callers to reimplement Vue template parsing with regular expressions.

Summary

Functions

Collect importable static asset references from an SFC template.

Collect SFC blocks whose contents are loaded through a src attribute.

Like external_sources/1 but raises Vize.Error on parse errors.

Rewrite asset literals in compiled SFC JavaScript to imported bindings.

Generate the deterministic scope ID used by Vize's bundler integrations.

Functions

collect_template_assets(source, opts \\ [])

@spec collect_template_assets(
  String.t(),
  keyword()
) :: {:ok, [Vize.SFC.Asset.t()]} | {:error, Vize.Error.t()}

Collect importable static asset references from an SFC template.

By default Vize recognizes assets such as img[src], video[src], video[poster], source[src], and SVG image/use references.

Options

  • :filename — filename used when parsing the SFC

collect_template_assets!(source, opts \\ [])

@spec collect_template_assets!(
  String.t(),
  keyword()
) :: [Vize.SFC.Asset.t()]

Like collect_template_assets/2 but raises Vize.Error on parse errors.

external_sources(source)

@spec external_sources(String.t()) ::
  {:ok, [Vize.SFC.ExternalSource.t()]} | {:error, Vize.Error.t()}

Collect SFC blocks whose contents are loaded through a src attribute.

Returns template, script, script-setup, style, and custom-block sources.

external_sources!(source)

@spec external_sources!(String.t()) :: [Vize.SFC.ExternalSource.t()]

Like external_sources/1 but raises Vize.Error on parse errors.

rewrite_asset_references(code, assets)

@spec rewrite_asset_references(String.t(), [Vize.SFC.Asset.t()]) :: String.t()

Rewrite asset literals in compiled SFC JavaScript to imported bindings.

assets should be the result of collect_template_assets/2. The function is total: JavaScript that cannot be parsed is returned unchanged.

scope_id(filename, opts \\ [])

@spec scope_id(
  String.t(),
  keyword()
) :: String.t()

Generate the deterministic scope ID used by Vize's bundler integrations.

Options

  • :root — project root used to normalize the filename
  • :production — use the production hashing strategy
  • :source — source content included by the production strategy