class Vite implements Htmlable (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected string|null $nonce

The Content Security Policy nonce to apply to all generated tags.

protected string|false $integrityKey

The key to check for integrity hashes within the manifest.

protected array $entryPoints

The configured entry points.

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 callable|null $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.

protected array $preloadedAssets

The preloaded assets.

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 $prefetchStrategy

The prefetching strategy 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, object|callable $macro)

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

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

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.

$this
useIntegrityKey(string|false $key)

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

$this
withEntryPoints(array $entryPoints)

Set the Vite entry points.

$this
mergeEntryPoints(array $entryPoints)

Merge additional Vite entry points with the current set.

$this
useManifestFilename(string $filename)

Set the filename for the manifest file.

$this
createAssetPathsUsing(callable|null $resolver)

Resolve asset paths using the provided resolver.

string
hotFile()

Get the Vite "hot" file path.

$this
useHotFile(string $path)

Set the Vite "hot" file path.

$this
useBuildDirectory(string $path)

Set the Vite build directory.

$this
useScriptTagAttributes($attributes)

Use the given callback to resolve attributes for script tags.

$this
useStyleTagAttributes($attributes)

Use the given callback to resolve attributes for style tags.

$this
usePreloadTagAttributes($attributes)

Use the given callback to resolve attributes for preload tags.

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

Eagerly prefetch assets.

$this
useWaterfallPrefetching(int|null $concurrency = null)

Use the "waterfall" prefetching strategy.

$this
useAggressivePrefetching()

Use the "aggressive" prefetching strategy.

$this
usePrefetchStrategy($strategy, array $config = [])

Set the prefetching strategy.

__invoke(string|string[] $entrypoints, string|null $buildDirectory = null)

Generate Vite tags for an entrypoint.

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

Make tag for the given chunk.

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

Make a preload tag for the given chunk.

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

Resolve the attributes for the chunks generated script tag.

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

Resolve the attributes for the chunks generated stylesheet tag.

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

Resolve the attributes for the chunks generated preload tag.

string
makeTag(string $url) deprecated

Generate an appropriate tag for the given URL in HMR mode.

string
makeScriptTag(string $url) deprecated

Generate a script tag for the given URL.

string
makeStylesheetTag(string $url) deprecated

Generate a stylesheet tag for the given URL in HMR mode.

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|void
reactRefresh()

Generate React refresh runtime script.

string
hotAsset($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(list<string>|string|null $aliases = null)

Render font preload links and inline styles.

string
renderFontPreloads(list<array<string,string>> $preloads)

Render preload link tags for font entries.

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

Resolve the attributes for a font preload tag.

string
renderFontStyle(array<string,mixed> $manifest, list<string>|null $aliases)

Render the inline style block for the font manifest.

viteFonts()

Get the ViteFonts instance.

$this
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.

void
flush()

Flush state.

Details

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

array preloadedAssets()

Get the preloaded assets.

Return Value

array

string|null cspNonce()

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

Return Value

string|null

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

$this useIntegrityKey(string|false $key)

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

Parameters

string|false $key

Return Value

$this

$this withEntryPoints(array $entryPoints)

Set the Vite entry points.

Parameters

array $entryPoints

Return Value

$this

$this mergeEntryPoints(array $entryPoints)

Merge additional Vite entry points with the current set.

Parameters

array $entryPoints

Return Value

$this

$this useManifestFilename(string $filename)

Set the filename for the manifest file.

Parameters

string $filename

Return Value

$this

$this createAssetPathsUsing(callable|null $resolver)

Resolve asset paths using the provided resolver.

Parameters

callable|null $resolver

Return Value

$this

string hotFile()

Get the Vite "hot" file path.

Return Value

string

$this useHotFile(string $path)

Set the Vite "hot" file path.

Parameters

string $path

Return Value

$this

$this useBuildDirectory(string $path)

Set the Vite build directory.

Parameters

string $path

Return Value

$this

$this useScriptTagAttributes($attributes)

Use the given callback to resolve attributes for script tags.

Parameters

$attributes

Return Value

$this

$this useStyleTagAttributes($attributes)

Use the given callback to resolve attributes for style tags.

Parameters

$attributes

Return Value

$this

$this usePreloadTagAttributes($attributes)

Use the given callback to resolve attributes for preload tags.

Parameters

$attributes

Return Value

$this

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

Eagerly prefetch assets.

Parameters

int|null $concurrency
string $event

Return Value

$this

$this useWaterfallPrefetching(int|null $concurrency = null)

Use the "waterfall" prefetching strategy.

Parameters

int|null $concurrency

Return Value

$this

$this useAggressivePrefetching()

Use the "aggressive" prefetching strategy.

Return Value

$this

$this usePrefetchStrategy($strategy, array $config = [])

Set the prefetching strategy.

Parameters

$strategy
array $config

Return Value

$this

HtmlString __invoke(string|string[] $entrypoints, string|null $buildDirectory = null)

Generate Vite tags for an entrypoint.

Parameters

string|string[] $entrypoints
string|null $buildDirectory

Return Value

HtmlString

Exceptions

Exception

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

Make tag for the given chunk.

Parameters

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

Return Value

string

protected string makePreloadTagForChunk(string $src, string $url, array $chunk, array $manifest)

Make a preload tag for the given chunk.

Parameters

string $src
string $url
array $chunk
array $manifest

Return Value

string

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

Resolve the attributes for the chunks generated script tag.

Parameters

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

Return Value

array

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

Resolve the attributes for the chunks generated stylesheet tag.

Parameters

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

Return Value

array

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

Resolve the attributes for the chunks generated preload tag.

Parameters

string $src
string $url
array $chunk
array $manifest

Return Value

array|false

protected string makeTag(string $url) deprecated

deprecated Will be removed in a future Laravel version.

Generate an appropriate tag for the given URL in HMR mode.

Parameters

string $url

Return Value

string

protected string makeScriptTag(string $url) deprecated

deprecated Will be removed in a future Laravel version.

Generate a script tag for the given URL.

Parameters

string $url

Return Value

string

protected string makeStylesheetTag(string $url) deprecated

deprecated Will be removed in a future Laravel version.

Generate a stylesheet tag for the given URL in HMR mode.

Parameters

string $url

Return Value

string

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

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

protected bool isCssPath(string $path)

Determine whether the given path is a CSS file.

Parameters

string $path

Return Value

bool

protected array parseAttributes(array $attributes)

Parse the attributes into key="value" strings.

Parameters

array $attributes

Return Value

array

HtmlString|void reactRefresh()

Generate React refresh runtime script.

Return Value

HtmlString|void

protected string hotAsset($asset)

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

Parameters

$asset

Return Value

string

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

Get the URL for an asset.

Parameters

string $asset
string|null $buildDirectory

Return Value

string

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

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

protected string publicPath(string $path)

Generate a public path for an asset.

Parameters

string $path

Return Value

string

protected array manifest(string $buildDirectory)

Get the manifest file for the given build directory.

Parameters

string $buildDirectory

Return Value

array

Exceptions

ViteManifestNotFoundException

protected string manifestPath(string $buildDirectory)

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

Parameters

string $buildDirectory

Return Value

string

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

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

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

protected HtmlString nonceAttribute()

Get the nonce attribute for the prefetch script tags.

Return Value

HtmlString

HtmlString fonts(list<string>|string|null $aliases = null)

Render font preload links and inline styles.

Parameters

list<string>|string|null $aliases

Return Value

HtmlString

Exceptions

ViteException

protected string renderFontPreloads(list<array<string,string>> $preloads)

Render preload link tags for font entries.

Parameters

list<array<string,string>> $preloads

Return Value

string

protected array<string,string|false>|false resolveFontPreloadAttributes(string $url, array<string,string> $preload)

Resolve the attributes for a font preload tag.

Parameters

string $url
array<string,string> $preload

Return Value

array<string,string|false>|false

protected string renderFontStyle(array<string,mixed> $manifest, list<string>|null $aliases)

Render the inline style block for the font manifest.

Parameters

array<string,mixed> $manifest
list<string>|null $aliases

Return Value

string

protected ViteFonts viteFonts()

Get the ViteFonts instance.

Return Value

ViteFonts

$this useFontsManifestFilename(string $filename)

Set the font manifest filename.

Parameters

string $filename

Return Value

$this

bool isRunningHot()

Determine if the HMR server is running.

Return Value

bool

string toHtml()

Get the Vite tag content as a string of HTML.

Return Value

string

void flush()

Flush state.

Return Value

void