final class Vite

Supports operations for Vite.

Constants

DEFAULT_DEV_SERVER

Fallback dev server URL used when no hot file is present.

Methods

static string
csrfToken()

Extracts value of csrf_token from hidden element.

static string
hotFile()

Absolute path to the "hot" file written by the chappyHot Vite plugin while npm run dev is running. It contains the dev server's public URL.

static bool
isRunningHot()

Determines if the Vite dev server is running by checking for the hot file.

static string
devServerUrl()

Returns the dev server URL without a trailing slash.

static bool
isDev()

Dev check. Dev assets are used only when APP_ENV is a dev-like environment AND the Vite dev server is running (hot file exists).

static bool
viteIsRunning(string|null $devBase = null) deprecated

Check if Vite dev server is reachable.

static string
devTags(string $entry, string $devServer)

Adds dev tags.

static array|null
loadManifest()

Locate and decode the Vite manifest.

static string
prodTags(string $entry)

Adds production tags.

static string
tags(string $entry, string|null $devServer = null)

Render script/link tags for a Vite entry.

Details

at line 16
static string csrfToken()

Extracts value of csrf_token from hidden element.

Return Value

string

The csrf_token.

at line 36
static string hotFile()

Absolute path to the "hot" file written by the chappyHot Vite plugin while npm run dev is running. It contains the dev server's public URL.

Return Value

string

Path to the hot file.

at line 46
static bool isRunningHot()

Determines if the Vite dev server is running by checking for the hot file.

Return Value

bool

True if the hot file exists, otherwise false.

at line 58
static string devServerUrl()

Returns the dev server URL without a trailing slash.

Resolution order: hot file contents, VITE_DEV_SERVER env variable, then DEFAULT_DEV_SERVER.

Return Value

string

The dev server URL.

at line 76
static bool isDev()

Dev check. Dev assets are used only when APP_ENV is a dev-like environment AND the Vite dev server is running (hot file exists).

Otherwise the built assets from the manifest are used.

Return Value

bool

at line 89
static bool viteIsRunning(string|null $devBase = null) deprecated

deprecated 4.0.4 Use Vite::isRunningHot() instead. This performs a network request on every call.

Check if Vite dev server is reachable.

Parameters

string|null $devBase

URL for dev server. Defaults to devServerUrl().

Return Value

bool

True if running, otherwise false.

at line 104
static private string devTags(string $entry, string $devServer)

Adds dev tags.

Parameters

string $entry

Relative path from project root (e.g. 'resources/js/app.jsx')

string $devServer

URL for dev server.

Return Value

string

Script modules with tags.

at line 120
static private array|null loadManifest()

Locate and decode the Vite manifest.

Return Value

array|null

The Vite manifest.

at line 157
static private string prodTags(string $entry)

Adds production tags.

Parameters

string $entry

Relative path from project root (e.g. 'resources/js/app.jsx')

Return Value

string

The production tags.

at line 224
static string tags(string $entry, string|null $devServer = null)

Render script/link tags for a Vite entry.

  • In dev (env=local/dev & hot file present), inject HMR client + raw module URL.
  • Otherwise use manifest-based assets.

Parameters

string $entry

Relative path from project root (e.g. 'resources/js/app.jsx')

string|null $devServer

URL for dev server. Defaults to devServerUrl().

Return Value

string

Script/link tags for a Vite entry.