Vite
class Vite implements Htmlable
Traits
Constants
| protected NONCE_CONTEXT_KEY |
The Content Security Policy nonce context key. |
| protected ENTRY_POINTS_CONTEXT_KEY |
The entry points context key. |
| protected PRELOADED_ASSETS_CONTEXT_KEY |
The preloaded assets context key. |
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| protected string|false | $integrityKey | The key to check for integrity hashes within the manifest. |
|
| protected string|null | $hotFile | The path to the "hot" file. |
|
| protected string | $buildDirectory | The path to the build directory. |
|
| protected string | $manifestFilename | The name of the manifest file. |
|
| protected | $assetPathResolver | The custom asset path resolver. |
|
| protected array | $scriptTagAttributesResolvers | The script tag attributes resolvers. |
|
| protected array | $styleTagAttributesResolvers | The style tag attributes resolvers. |
|
| protected array | $preloadTagAttributesResolvers | The preload tag attributes resolvers. |
|
| static protected array | $manifests | The cached manifest files. |
|
| protected ViteFonts|null | $fonts | The ViteFonts instance. |
|
| protected string | $fontsManifestFilename | The name of the font manifest file. |
|
| protected string|null | $prefetchStrategy | The prefetching strategy (waterfall or aggressive) to use. |
|
| protected int | $prefetchConcurrently | The number of assets to load concurrently when using the "waterfall" strategy. |
|
| protected string | $prefetchEvent | The name of the event that should trigger prefetching. The event must be dispatched on the |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Get the preloaded assets.
No description
Get the Content Security Policy nonce applied to all generated tags.
Generate or set a Content Security Policy nonce to apply to all generated tags.
Use the given key to detect integrity hashes in the manifest.
Set the Vite entry points.
Merge additional Vite entry points with the current set.
Set the filename for the manifest file.
Resolve asset paths using the provided resolver.
Get the Vite "hot" file path.
Set the Vite "hot" file path.
Set the Vite build directory.
Use the given callback to resolve attributes for script tags.
Use the given callback to resolve attributes for style tags.
Use the given callback to resolve attributes for preload tags.
Use the "waterfall" prefetching strategy.
Use the "aggressive" prefetching strategy.
Set the prefetching strategy.
Generate Vite tags for an entrypoint.
Make tag for the given chunk.
Make a preload tag for the given chunk.
Resolve the attributes for the chunks generated script tag.
Resolve the attributes for the chunks generated stylesheet tag.
Resolve the attributes for the chunks generated preload tag.
Generate a script tag with attributes for the given URL.
Generate a link tag with attributes for the given URL.
Determine whether the given path is a CSS file.
Parse the attributes into key="value" strings.
Generate React refresh runtime script.
Get the path to a given asset when running in HMR mode.
Get the URL for an asset.
Get the content of a given asset.
Generate an asset path for the application.
Generate a public path for an asset.
Get the manifest file for the given build directory.
Get the path to the manifest file for the given build directory.
Get a unique hash representing the current manifest, or null if there is no manifest.
Recursively resolve all imports for the given chunk.
Get the chunk for the given entry point / asset.
Get the nonce attribute for the prefetch script tags.
Render font preload links and inline styles.
Render preload link tags for font entries.
Resolve the attributes for a font preload tag.
Render the inline style block for the font manifest.
Set the font manifest filename.
Determine if the HMR server is running.
Get the Vite tag content as a string of HTML.
Flush all Vite state.
Details
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 110
array
preloadedAssets()
Get the preloaded assets.
at line 115
protected void
setPreloadedAssets(array $preloadedAssets)
No description
at line 123
string|null
cspNonce()
Get the Content Security Policy nonce applied to all generated tags.
at line 131
string
useCspNonce(string|null $nonce = null)
Generate or set a Content Security Policy nonce to apply to all generated tags.
at line 145
Vite
useIntegrityKey(string|false $key)
Use the given key to detect integrity hashes in the manifest.
Boot-only. The key is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 155
Vite
withEntryPoints(array $entryPoints)
Set the Vite entry points.
at line 165
Vite
mergeEntryPoints(array $entryPoints)
Merge additional Vite entry points with the current set.
at line 181
Vite
useManifestFilename(string $filename)
Set the filename for the manifest file.
Boot-only. The filename is stored on the shared Vite instance and affects every subsequent manifest lookup by this worker.
at line 194
Vite
createAssetPathsUsing(callable|null $resolver)
Resolve asset paths using the provided resolver.
Boot-only. The resolver is stored on the shared Vite instance and affects every subsequent asset path generated by this worker.
at line 204
string
hotFile()
Get the Vite "hot" file path.
at line 215
Vite
useHotFile(string $path)
Set the Vite "hot" file path.
Boot-only. The path is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 228
Vite
useBuildDirectory(string $path)
Set the Vite build directory.
Boot-only. The directory is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 243
Vite
useScriptTagAttributes(callable|array $attributes)
Use the given callback to resolve attributes for script tags.
Boot-only. The resolver persists on the shared Vite instance and affects every subsequent asset render by this worker.
at line 262
Vite
useStyleTagAttributes(callable|array $attributes)
Use the given callback to resolve attributes for style tags.
Boot-only. The resolver persists on the shared Vite instance and affects every subsequent asset render by this worker.
at line 281
Vite
usePreloadTagAttributes(callable|array|false $attributes)
Use the given callback to resolve attributes for preload tags.
Boot-only. The resolver persists on the shared Vite instance and affects every subsequent asset render by this worker.
at line 298
Vite
prefetch(int|null $concurrency = null, string $event = 'load')
Eagerly prefetch assets.
Boot-only. The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 313
Vite
useWaterfallPrefetching(int|null $concurrency = null)
Use the "waterfall" prefetching strategy.
Boot-only. The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 326
Vite
useAggressivePrefetching()
Use the "aggressive" prefetching strategy.
Boot-only. The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 339
Vite
usePrefetchStrategy(string|null $strategy, array $config = [])
Set the prefetching strategy.
Boot-only. The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 353
HtmlString
__invoke(string|array $entrypoints, string|null $buildDirectory = null)
Generate Vite tags for an entrypoint.
at line 571
protected string
makeTagForChunk(string|null $src, string $url, array|null $chunk, array|null $manifest)
Make tag for the given chunk.
at line 600
protected string
makePreloadTagForChunk(string|null $src, string $url, array|null $chunk, array $manifest)
Make a preload tag for the given chunk.
at line 620
protected array
resolveScriptTagAttributes(string|null $src, string $url, array|null $chunk, array|null $manifest)
Resolve the attributes for the chunks generated script tag.
at line 636
protected array
resolveStylesheetTagAttributes(string|null $src, string $url, array|null $chunk, array|null $manifest)
Resolve the attributes for the chunks generated stylesheet tag.
at line 652
protected array|false
resolvePreloadTagAttributes(string|null $src, string $url, array|null $chunk, array $manifest)
Resolve the attributes for the chunks generated preload tag.
at line 686
protected string
makeScriptTagWithAttributes(string $url, array $attributes)
Generate a script tag with attributes for the given URL.
at line 700
protected string
makeStylesheetTagWithAttributes(string $url, array $attributes)
Generate a link tag with attributes for the given URL.
at line 714
protected bool
isCssPath(string $path)
Determine whether the given path is a CSS file.
at line 722
protected array
parseAttributes(array $attributes)
Parse the attributes into key="value" strings.
at line 735
HtmlString|null
reactRefresh()
Generate React refresh runtime script.
at line 765
protected string
hotAsset(string $asset)
Get the path to a given asset when running in HMR mode.
at line 780
string
asset(string $asset, string|null $buildDirectory = null)
Get the URL for an asset.
at line 798
string
content(string $asset, string|null $buildDirectory = null)
Get the content of a given asset.
at line 822
protected string
assetPath(string $path, bool|null $secure = null)
Generate an asset path for the application.
at line 830
protected string
publicPath(string $path)
Generate a public path for an asset.
at line 840
protected array
manifest(string $buildDirectory)
Get the manifest file for the given build directory.
at line 874
protected string
manifestPath(string $buildDirectory)
Get the path to the manifest file for the given build directory.
at line 882
string|null
manifestHash(string|null $buildDirectory = null)
Get a unique hash representing the current manifest, or null if there is no manifest.
at line 900
protected array
resolveImports(array $manifest, array $chunk, array $seen = [])
Recursively resolve all imports for the given chunk.
at line 926
protected array
chunk(array $manifest, string $file)
Get the chunk for the given entry point / asset.
at line 938
protected HtmlString
nonceAttribute()
Get the nonce attribute for the prefetch script tags.
at line 954
HtmlString
fonts(array|string|null $aliases = null)
Render font preload links and inline styles.
at line 996
protected string
renderFontPreloads(array $preloads)
Render preload link tags for font entries.
at line 1032
protected array|false
resolveFontPreloadAttributes(string $url, array $preload)
Resolve the attributes for a font preload tag.
at line 1060
protected string
renderFontStyle(array $manifest, array|null $aliases)
Render the inline style block for the font manifest.
at line 1080
protected ViteFonts
viteFonts()
Get the ViteFonts instance.
at line 1091
Vite
useFontsManifestFilename(string $filename)
Set the font manifest filename.
Boot-only. The filename is stored on the shared Vite instance and affects every subsequent font manifest lookup by this worker.
at line 1101
bool
isRunningHot()
Determine if the HMR server is running.
at line 1109
string
toHtml()
Get the Vite tag content as a string of HTML.
at line 1122
static void
flush()
Flush all Vite state.
Boot or tests only. Clears worker-wide Vite manifests and request-local context used by subsequent asset rendering.