Asset ViewHelper <vite:asset>
The <vite: ViewHelper embeds all JavaScript and CSS belonging to the
specified vite entry using TYPO3's AssetCollector API. It automatically
switches between Vite's development server and production rendering
(manifest.json) based on the extension's configuration.
Assets are embedded with the following defaults:
- Scripts are embedded as JavaScript modules using
<script type="module">at the end of the document - CSS files use
<link rel="stylesheet">in the<head> - Imported JavaScript modules are preloaded automatically using
<link rel="modulepreload"> - Referenced fonts in the woff2 format are preloaded automatically using
<link rel="preload">
These defaults can be configured by nesting
<vite:asset.script>,
<vite:asset.css>,
<vite:asset.font>
and/or
<vite:asset.image>
inside <vite: (see examples below). Each of them can be used once.
Example: Basic usage
<vite:asset entry="EXT:sitepackage/Resources/Private/JavaScript/Main.entry.js" />
Copied!
Example: Inlining CSS
<vite:asset entry="EXT:sitepackage/Resources/Private/JavaScript/Main.entry.js">
<vite:asset.css inline="{true}" />
</vite:asset>
Copied!
Example: Disable automatic preloading
<vite:asset entry="EXT:sitepackage/Resources/Private/JavaScript/Main.entry.js">
<vite:asset.script preloadImports="{false}" />
<vite:asset.font preload="{false}" />
</vite:asset>
Copied!
Example: Media query for CSS
<vite:asset entry="EXT:sitepackage/Resources/Private/Css/Print.entry.css">
<vite:asset.css media="print" />
</vite:asset>
Copied!
Arguments
The following arguments are available for the asset ViewHelper:
addCss
-
- Type
- boolean
- Default
- true
Deprecated, use <vite:asset.css> instead. (If set to "false", CSS files associated with the entry point won't be added to the asset collector)
csp
-
- Type
- bool
Whether to collect a CSP hash value for this asset (default: true for external files, false for inline)
cssTagAttributes
-
- Type
- array
- Default
- array ( )
Deprecated, use <vite:asset.css> instead. (Additional HTML attributes for css link tags.)
entry
-
- Type
- string
Identifier of the desired vite entrypoint; this is the value specified as "input" in the vite configuration file. Can be omitted if manifest file exists and only one entrypoint is present.
inlineCss
-
- Type
- boolean
- Default
- false
Deprecated, use <vite:asset.css> instead. (If set to "true", CSS will be added as inline <style> tag.)
manifest
-
- Type
- string
Path to your manifest.json file. If omitted, default manifest from extension configuration will be used instead.
priority
-
- Type
- boolean
- Default
- false
Deprecated, use <vite:asset.css> for CSS and <vite:asset.script> for scripts instead. (Include assets before other assets in HTML)
scriptTagAttributes
-
- Type
- array
- Default
- array ( )
Deprecated, use <vite:asset.script> instead. (Additional HTML attributes for script tags)
useNonce
-
- Type
- bool
Deprecated, use csp instead. (Whether to use the global nonce value)