Skip to content

View Helpers

viteScriptTag()

viteScriptTag() — returns string

Available in: controller Category: Asset Functions

Returns ‘script’ tags for a Vite JS entrypoint. In development, also injects the Vite client for Hot Module Replacement (HMR). In production, includes any associated CSS files from the manifest as tags.

NameTypeRequiredDefaultDescription
entrypointstringyes—The source entrypoint path (e.g. “src/main.js”).
headbooleannofalseSet to true to place output in the <head> area instead of inline.
// 1. Emit a script tag for a Vite JS entrypoint inline (default)
// In development, also injects the Vite HMR client.
// In production, emits <link> tags for any associated CSS and a <script type="module"> tag.
writeOutput(viteScriptTag("src/main.js"));

// 2. Place the script tag in the <head> instead of inline
// Passes the generated markup to $htmlHead() so it is buffered into the page <head>.
// Returns an empty string; nothing is printed at the call site.
viteScriptTag(entrypoint="src/main.js", head=true);

// 3. Emit a script tag for a page-specific entrypoint
// Each entrypoint gets its own script tag; CSS chunks discovered in the
// manifest are automatically included as <link rel="stylesheet"> tags.
writeOutput(viteScriptTag("src/checkout.js"));