Volt.JS.Transforms.AssetURLs (Volt v0.13.0)

Copy Markdown View Source

Rewrites new URL("./asset.ext", import.meta.url) references to asset imports.

Vite treats relative asset URL constructors as part of the module graph so production builds can copy, hash, and rewrite the referenced file. Volt does the same by converting the asset argument into a generated ?url import before the normal import rewriting and bundling phases run.

Only relative specifiers that point at known static asset extensions are rewritten. Absolute URLs, package URLs, and non-asset files are left unchanged.

Summary

Functions

Rewrites matching asset URL constructors in source.

Functions

rewrite(source, filename)

@spec rewrite(String.t(), String.t()) :: String.t()

Rewrites matching asset URL constructors in source.

Returns the original source unchanged when parsing fails or no matching constructor is found.