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 window.

Methods

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

array
preloadedAssets()

Get the preloaded assets.

void
setPreloadedAssets(array $preloadedAssets)

No description

string|null
cspNonce()

Get the Content Security Policy nonce applied to all generated tags.

string
useCspNonce(string|null $nonce = null)

Generate or set a Content Security Policy nonce to apply to all generated tags.

useIntegrityKey(string|false $key)

Use the given key to detect integrity hashes in the manifest.

withEntryPoints(array $entryPoints)

Set the Vite entry points.

mergeEntryPoints(array $entryPoints)

Merge additional Vite entry points with the current set.

useManifestFilename(string $filename)

Set the filename for the manifest file.

createAssetPathsUsing(callable|null $resolver)

Resolve asset paths using the provided resolver.

string
hotFile()

Get the Vite "hot" file path.

useHotFile(string $path)

Set the Vite "hot" file path.

useBuildDirectory(string $path)

Set the Vite build directory.

useScriptTagAttributes(callable|array $attributes)

Use the given callback to resolve attributes for script tags.

useStyleTagAttributes(callable|array $attributes)

Use the given callback to resolve attributes for style tags.

usePreloadTagAttributes(callable|array|false $attributes)

Use the given callback to resolve attributes for preload tags.

prefetch(int|null $concurrency = null, string $event = 'load')

Eagerly prefetch assets.

useWaterfallPrefetching(int|null $concurrency = null)

Use the "waterfall" prefetching strategy.

useAggressivePrefetching()

Use the "aggressive" prefetching strategy.

usePrefetchStrategy(string|null $strategy, array $config = [])

Set the prefetching strategy.

__invoke(string|array $entrypoints, string|null $buildDirectory = null)

Generate Vite tags for an entrypoint.

string
makeTagForChunk(string|null $src, string $url, array|null $chunk, array|null $manifest)

Make tag for the given chunk.

string
makePreloadTagForChunk(string|null $src, string $url, array|null $chunk, array $manifest)

Make a preload tag for the given chunk.

array
resolveScriptTagAttributes(string|null $src, string $url, array|null $chunk, array|null $manifest)

Resolve the attributes for the chunks generated script tag.

array
resolveStylesheetTagAttributes(string|null $src, string $url, array|null $chunk, array|null $manifest)

Resolve the attributes for the chunks generated stylesheet tag.

array|false
resolvePreloadTagAttributes(string|null $src, string $url, array|null $chunk, array $manifest)

Resolve the attributes for the chunks generated preload tag.

string
makeScriptTagWithAttributes(string $url, array $attributes)

Generate a script tag with attributes for the given URL.

string
makeStylesheetTagWithAttributes(string $url, array $attributes)

Generate a link tag with attributes for the given URL.

bool
isCssPath(string $path)

Determine whether the given path is a CSS file.

array
parseAttributes(array $attributes)

Parse the attributes into key="value" strings.

HtmlString|null
reactRefresh()

Generate React refresh runtime script.

string
hotAsset(string $asset)

Get the path to a given asset when running in HMR mode.

string
asset(string $asset, string|null $buildDirectory = null)

Get the URL for an asset.

string
content(string $asset, string|null $buildDirectory = null)

Get the content of a given asset.

string
assetPath(string $path, bool|null $secure = null)

Generate an asset path for the application.

string
publicPath(string $path)

Generate a public path for an asset.

array
manifest(string $buildDirectory)

Get the manifest file for the given build directory.

string
manifestPath(string $buildDirectory)

Get the path to the manifest file for the given build directory.

string|null
manifestHash(string|null $buildDirectory = null)

Get a unique hash representing the current manifest, or null if there is no manifest.

array
resolveImports(array $manifest, array $chunk, array $seen = [])

Recursively resolve all imports for the given chunk.

array
chunk(array $manifest, string $file)

Get the chunk for the given entry point / asset.

nonceAttribute()

Get the nonce attribute for the prefetch script tags.

fonts(array|string|null $aliases = null)

Render font preload links and inline styles.

string
renderFontPreloads(array $preloads)

Render preload link tags for font entries.

array|false
resolveFontPreloadAttributes(string $url, array $preload)

Resolve the attributes for a font preload tag.

string
renderFontStyle(array $manifest, array|null $aliases)

Render the inline style block for the font manifest.

viteFonts()

Get the ViteFonts instance.

useFontsManifestFilename(string $filename)

Set the font manifest filename.

bool
isRunningHot()

Determine if the HMR server is running.

string
toHtml()

Get the Vite tag content as a string of HTML.

static void
flush()

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.

Parameters

string $name
callable|object $macro

Return Value

void

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.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

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.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

at line 110
array preloadedAssets()

Get the preloaded assets.

Return Value

array

at line 115
protected void setPreloadedAssets(array $preloadedAssets)

No description

Parameters

array $preloadedAssets

Return Value

void

at line 123
string|null cspNonce()

Get the Content Security Policy nonce applied to all generated tags.

Return Value

string|null

at line 131
string useCspNonce(string|null $nonce = null)

Generate or set a Content Security Policy nonce to apply to all generated tags.

Parameters

string|null $nonce

Return Value

string

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.

Parameters

string|false $key

Return Value

Vite

at line 155
Vite withEntryPoints(array $entryPoints)

Set the Vite entry points.

Parameters

array $entryPoints

Return Value

Vite

at line 165
Vite mergeEntryPoints(array $entryPoints)

Merge additional Vite entry points with the current set.

Parameters

array $entryPoints

Return Value

Vite

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.

Parameters

string $filename

Return Value

Vite

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.

Parameters

callable|null $resolver

Return Value

Vite

at line 204
string hotFile()

Get the Vite "hot" file path.

Return Value

string

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.

Parameters

string $path

Return Value

Vite

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.

Parameters

string $path

Return Value

Vite

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.

Parameters

callable|array $attributes

Return Value

Vite

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.

Parameters

callable|array $attributes

Return Value

Vite

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.

Parameters

callable|array|false $attributes

Return Value

Vite

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.

Parameters

int|null $concurrency
string $event

Return Value

Vite

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.

Parameters

int|null $concurrency

Return Value

Vite

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.

Return Value

Vite

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.

Parameters

string|null $strategy
array $config

Return Value

Vite

Exceptions

Exception

at line 353
HtmlString __invoke(string|array $entrypoints, string|null $buildDirectory = null)

Generate Vite tags for an entrypoint.

Parameters

string|array $entrypoints
string|null $buildDirectory

Return Value

HtmlString

at line 571
protected string makeTagForChunk(string|null $src, string $url, array|null $chunk, array|null $manifest)

Make tag for the given chunk.

Parameters

string|null $src
string $url
array|null $chunk
array|null $manifest

Return Value

string

at line 600
protected string makePreloadTagForChunk(string|null $src, string $url, array|null $chunk, array $manifest)

Make a preload tag for the given chunk.

Parameters

string|null $src
string $url
array|null $chunk
array $manifest

Return Value

string

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.

Parameters

string|null $src
string $url
array|null $chunk
array|null $manifest

Return Value

array

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.

Parameters

string|null $src
string $url
array|null $chunk
array|null $manifest

Return Value

array

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.

Parameters

string|null $src
string $url
array|null $chunk
array $manifest

Return Value

array|false

at line 686
protected string makeScriptTagWithAttributes(string $url, array $attributes)

Generate a script tag with attributes for the given URL.

Parameters

string $url
array $attributes

Return Value

string

at line 700
protected string makeStylesheetTagWithAttributes(string $url, array $attributes)

Generate a link tag with attributes for the given URL.

Parameters

string $url
array $attributes

Return Value

string

at line 714
protected bool isCssPath(string $path)

Determine whether the given path is a CSS file.

Parameters

string $path

Return Value

bool

at line 722
protected array parseAttributes(array $attributes)

Parse the attributes into key="value" strings.

Parameters

array $attributes

Return Value

array

at line 735
HtmlString|null reactRefresh()

Generate React refresh runtime script.

Return Value

HtmlString|null

at line 765
protected string hotAsset(string $asset)

Get the path to a given asset when running in HMR mode.

Parameters

string $asset

Return Value

string

at line 780
string asset(string $asset, string|null $buildDirectory = null)

Get the URL for an asset.

Parameters

string $asset
string|null $buildDirectory

Return Value

string

at line 798
string content(string $asset, string|null $buildDirectory = null)

Get the content of a given asset.

Parameters

string $asset
string|null $buildDirectory

Return Value

string

Exceptions

ViteException

at line 822
protected string assetPath(string $path, bool|null $secure = null)

Generate an asset path for the application.

Parameters

string $path
bool|null $secure

Return Value

string

at line 830
protected string publicPath(string $path)

Generate a public path for an asset.

Parameters

string $path

Return Value

string

at line 840
protected array manifest(string $buildDirectory)

Get the manifest file for the given build directory.

Parameters

string $buildDirectory

Return Value

array

Exceptions

ViteException

at line 874
protected string manifestPath(string $buildDirectory)

Get the path to the manifest file for the given build directory.

Parameters

string $buildDirectory

Return Value

string

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.

Parameters

string|null $buildDirectory

Return Value

string|null

at line 900
protected array resolveImports(array $manifest, array $chunk, array $seen = [])

Recursively resolve all imports for the given chunk.

Parameters

array $manifest
array $chunk
array $seen

Return Value

array

at line 926
protected array chunk(array $manifest, string $file)

Get the chunk for the given entry point / asset.

Parameters

array $manifest
string $file

Return Value

array

Exceptions

ViteException

at line 938
protected HtmlString nonceAttribute()

Get the nonce attribute for the prefetch script tags.

Return Value

HtmlString

at line 954
HtmlString fonts(array|string|null $aliases = null)

Render font preload links and inline styles.

Parameters

array|string|null $aliases

Return Value

HtmlString

Exceptions

ViteException

at line 996
protected string renderFontPreloads(array $preloads)

Render preload link tags for font entries.

Parameters

array $preloads

Return Value

string

at line 1032
protected array|false resolveFontPreloadAttributes(string $url, array $preload)

Resolve the attributes for a font preload tag.

Parameters

string $url
array $preload

Return Value

array|false

at line 1060
protected string renderFontStyle(array $manifest, array|null $aliases)

Render the inline style block for the font manifest.

Parameters

array $manifest
array|null $aliases

Return Value

string

at line 1080
protected ViteFonts viteFonts()

Get the ViteFonts instance.

Return Value

ViteFonts

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.

Parameters

string $filename

Return Value

Vite

at line 1101
bool isRunningHot()

Determine if the HMR server is running.

Return Value

bool

at line 1109
string toHtml()

Get the Vite tag content as a string of HTML.

Return Value

string

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.

Return Value

void