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 of the running Vite development server.
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 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 112
array
preloadedAssets()
Get the preloaded assets.
at line 117
protected void
setPreloadedAssets(array $preloadedAssets)
No description
at line 125
string|null
cspNonce()
Get the Content Security Policy nonce applied to all generated tags.
at line 133
string
useCspNonce(string|null $nonce = null)
Generate or set a Content Security Policy nonce to apply to all generated tags.
at line 149
Vite
useIntegrityKey(string|false $key)
Use the given key to detect integrity hashes in the manifest.
The key is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 162
Vite
withEntryPoints(array $entryPoints)
Set the Vite entry points.
at line 174
Vite
mergeEntryPoints(array $entryPoints)
Merge additional Vite entry points with the current set.
at line 192
Vite
useManifestFilename(string $filename)
Set the filename for the manifest file.
The filename is stored on the shared Vite instance and affects every subsequent manifest lookup by this worker.
at line 208
Vite
createAssetPathsUsing(callable|null $resolver)
Resolve asset paths using the provided resolver.
The resolver is stored on the shared Vite instance and affects every subsequent asset path generated by this worker.
at line 219
string
hotFile()
Get the Vite "hot" file path.
at line 232
Vite
useHotFile(string $path)
Set the Vite "hot" file path.
The path is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 248
Vite
useBuildDirectory(string $path)
Set the Vite build directory.
The directory is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 265
Vite
useScriptTagAttributes(callable|array $attributes)
Use the given callback to resolve attributes for script tags.
The resolver persists on the shared Vite instance and affects every subsequent asset render by this worker.
at line 286
Vite
useStyleTagAttributes(callable|array $attributes)
Use the given callback to resolve attributes for style tags.
The resolver persists on the shared Vite instance and affects every subsequent asset render by this worker.
at line 307
Vite
usePreloadTagAttributes(callable|array|false $attributes)
Use the given callback to resolve attributes for preload tags.
The resolver persists on the shared Vite instance and affects every subsequent asset render by this worker.
at line 327
Vite
prefetch(int|null $concurrency = null, string $event = 'load')
Eagerly prefetch assets.
The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 345
Vite
useWaterfallPrefetching(int|null $concurrency = null)
Use the "waterfall" prefetching strategy.
The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 361
Vite
useAggressivePrefetching()
Use the "aggressive" prefetching strategy.
The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 377
Vite
usePrefetchStrategy(string|null $strategy, array $config = [])
Set the prefetching strategy.
The strategy is stored on the shared Vite instance and affects every subsequent asset render by this worker.
at line 392
HtmlString
__invoke(string|array $entrypoints, string|null $buildDirectory = null)
Generate Vite tags for an entrypoint.
at line 610
protected string
makeTagForChunk(string|null $src, string $url, array|null $chunk, array|null $manifest)
Make tag for the given chunk.
at line 639
protected string
makePreloadTagForChunk(string|null $src, string $url, array|null $chunk, array $manifest)
Make a preload tag for the given chunk.
at line 659
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 675
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 691
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 727
protected string
makeScriptTagWithAttributes(string $url, array $attributes)
Generate a script tag with attributes for the given URL.
at line 741
protected string
makeStylesheetTagWithAttributes(string $url, array $attributes)
Generate a link tag with attributes for the given URL.
at line 755
protected bool
isCssPath(string $path)
Determine whether the given path is a CSS file.
at line 763
protected array
parseAttributes(array $attributes)
Parse the attributes into key="value" strings.
at line 776
HtmlString|null
reactRefresh()
Generate React refresh runtime script.
at line 806
protected string
hotAsset(string $asset)
Get the path to a given asset when running in HMR mode.
at line 817
string|null
devServerUrl()
Get the URL of the running Vite development server.
at line 836
string
asset(string $asset, string|null $buildDirectory = null)
Get the URL for an asset.
at line 854
string
content(string $asset, string|null $buildDirectory = null)
Get the content of a given asset.
at line 878
protected string
assetPath(string $path, bool|null $secure = null)
Generate an asset path for the application.
at line 886
protected string
publicPath(string $path)
Generate a public path for an asset.
at line 896
protected array
manifest(string $buildDirectory)
Get the manifest file for the given build directory.
at line 930
protected string
manifestPath(string $buildDirectory)
Get the path to the manifest file for the given build directory.
at line 938
string|null
manifestHash(string|null $buildDirectory = null)
Get a unique hash representing the current manifest, or null if there is no manifest.
at line 956
protected array
resolveImports(array $manifest, array $chunk, array $seen = [])
Recursively resolve all imports for the given chunk.
at line 982
protected array
chunk(array $manifest, string $file)
Get the chunk for the given entry point / asset.
at line 994
protected HtmlString
nonceAttribute()
Get the nonce attribute for the prefetch script tags.
at line 1010
HtmlString
fonts(array|string|null $aliases = null)
Render font preload links and inline styles.
at line 1052
protected string
renderFontPreloads(array $preloads)
Render preload link tags for font entries.
at line 1088
protected array|false
resolveFontPreloadAttributes(string $url, array $preload)
Resolve the attributes for a font preload tag.
at line 1116
protected string
renderFontStyle(array $manifest, array|null $aliases)
Render the inline style block for the font manifest.
at line 1136
protected ViteFonts
viteFonts()
Get the ViteFonts instance.
at line 1149
Vite
useFontsManifestFilename(string $filename)
Set the font manifest filename.
The filename is stored on the shared Vite instance and affects every subsequent font manifest lookup by this worker.
at line 1160
bool
isRunningHot()
Determine if the HMR server is running.
at line 1168
string
toHtml()
Get the Vite tag content as a string of HTML.
at line 1181
static void
flush()
Flush all Vite state.
Clears worker-wide Vite manifests and request-local context used by subsequent asset rendering.