View Helpers
viteScriptTag()
Signature
Section titled “Signature”viteScriptTag() — returns string
Available in: controller
Category: Asset Functions
Description
Section titled “Description”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.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
entrypoint | string | yes | — | The source entrypoint path (e.g. “src/main.js”). |
head | boolean | no | false | Set to true to place output in the <head> area instead of inline. |
Examples
Section titled “Examples”// 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"));