Skip to content

PHP API & Troubleshooting

Vite exposes $this->wire()->vite (an instance of ProcessWire\Vite delegating to Totoglu\Vite\Vite) and the global template helper vite($entries = null).

Method Signature / Behavior
vite($entries = null) Global helper (functions.php). Returns the active Totoglu\Vite\Vite instance, or renders tags immediately when $entries (string or array) is passed.
instance() Returns the underlying Totoglu\Vite\Vite singleton configured from module settings and setting('vite').
copy() Clones the current Totoglu\Vite\Vite instance with identical configuration so fluent changes never leak across requests or builds.
flush(bool $clearManifests = false) Resets queued entries, preloaded assets, and optional static manifest cache.
withEntries(string|array $entries) Appends one or more entrypoint paths (supports @ optional prefix) and returns $this for fluent chaining.
__invoke(string|array $entries, ?string $buildDirectory = null) Invokable shorthand that resolves and renders <link> and <script> HTML tags.
__toString() Renders all queued entries (from withEntries()) into HTML tags.
withReactRefresh() Prepends the React Fast Refresh preamble in hot mode (no-op in production).
reactRefresh() Returns the standalone React Fast Refresh <script type="module"> string in hot mode, or '' in production.
asset(string $asset, ?string $buildDirectory = null) Resolves a single static asset path to its dev server URL (hot mode) or hashed production URL (manifest mode).
url(string $path) Normalizes and prefixes a relative asset path with rootUrl.
hotAsset(string $asset) Builds the full dev server URL for an asset using the origin stored in hotFile.
hotFile() Returns the resolved absolute path to the configured hot file.
isRunningHot() Returns true when hotFile() exists on disk.
nonce() Returns the active CSP nonce string or null.
preloadedAssets() Returns the map of <link rel="modulepreload"> asset URLs emitted during the current render.
useRootPath(string $path) Overrides the filesystem root directory containing buildDirectory and hotFile.
useRootUrl(string $url) Overrides the public URL prefix for production assets.
useBuildDirectory(string $path) Overrides the build output subdirectory (default 'build').
useHotFile(string $path) Overrides the hot file path (default 'hot').
useManifest(string $filename) Overrides the manifest filename (default 'manifest.json').
useIntegrity(string|false $key) Sets the manifest SRI key (default 'integrity') or disables SRI with false.
useNonce(?string $nonce) Sets or clears the CSP nonce applied to emitted tags.
useScriptTagAttributes(array|callable $attributes) Adds custom attributes to emitted <script> tags.
useStyleTagAttributes(array|callable $attributes) Adds custom attributes to emitted <link rel="stylesheet"> tags.
usePreloadTagAttributes(array|callable $attributes) Adds custom attributes to emitted <link rel="modulepreload"> tags.
normalizeConfigValue(mixed $value) Normalizes empty strings and raw config values cleanly when merging module settings.

Symptom: Vite manifest not found at: .../site/templates/build/manifest.json (or .vite/manifest.json).

Fix:

  1. Confirm you ran npm run build and build.manifest: true is enabled in vite.config.ts.
  2. Verify rootPath and buildDirectory match Vite’s build.outDir.
  3. Check that manifest is 'manifest.json' (Vite 5+ writes to build/.vite/manifest.json, which Vite checks automatically).

Production Site Tries to Load http://localhost:5173

Section titled “Production Site Tries to Load http://localhost:5173”

Symptom: Browser console shows failed requests to localhost:5173/@vite/client on staging or production.

Fix: Delete the stale hot file from site/templates/hot (or your custom hotFile path) and add it to .gitignore.

Symptom: Unable to locate file in Vite manifest: resources/ts/templates/home.ts.

Fix:

  • Add the file to build.rollupOptions.input in vite.config.ts and rebuild, or
  • Prefix the entry with @ ("@resources/ts/templates/{$page->template->name}.ts") if it is intentionally optional.

Duplicate CSS or Missing Transitive Styles

Section titled “Duplicate CSS or Missing Transitive Styles”

Symptom: Styles imported inside a shared TypeScript chunk do not appear.

Fix: Always import CSS inside your Vite entrypoints (not via raw <link> tags) and let Vite resolve the entry through vite([...]) so recursive imports and css traversal picks up all transitive stylesheets automatically.

Next steps