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.

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
useManifestFilename(string $filename)

Set the filename for the manifest file.

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

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

array
manifest(string $buildDirectory)

Get the 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
chunk(array $manifest, string $file)

Get the chunk for the given entry point / asset.

bool
isRunningHot()

Determine if the HMR server is running.

string
toHtml()

Get the Vite tag content as a string of HTML.

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 useManifestFilename(string $filename)

Set the filename for the manifest file.

Parameters

string $filename

Return Value

$this

$this createAssetPathsUsing($resolver)

Resolve asset paths using the provided resolver.

Parameters

$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

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

Exception

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 array manifest(string $buildDirectory)

Get the 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 chunk(array $manifest, string $file)

Get the chunk for the given entry point / asset.

Parameters

array $manifest
string $file

Return Value

array

Exceptions

Exception

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