Volt.JS.Transforms.DynamicImports (Volt v0.14.0)

Copy Markdown View Source

Rewrites relative template-literal dynamic imports into import maps.

JavaScript bundlers cannot statically follow import(./pages/${name}.ts) without first expanding the possible files. Volt rewrites those imports through import.meta.glob() so the normal glob transform can add the matching modules to the dev and production graphs.

The transform intentionally supports the same conservative shape Vite supports best: relative template literals with at least one expression. Bare package imports and absolute URLs are left untouched.

Helper code is generated from OXC templates and spliced into parsed source so the emitted JavaScript remains parser-validated.

Summary

Functions

Transforms relative template-literal dynamic imports in source.

Functions

transform(source, filename \\ "dynamic-import-vars.ts")

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

Transforms relative template-literal dynamic imports in source.

Returns the original source unchanged when parsing fails or no supported dynamic import is found.