Why Vite?
Modern frontend toolchains split TypeScript, CSS, and vendor chunks into content-hashed files so browsers can cache them aggressively. Writing ad-hoc PHP snippets to read manifest.json breaks quickly when you add code-splitting, CSS imported from shared chunks, React Fast Refresh, or strict Content Security Policies.
Vite Module vs. Manual Asset Helpers
Section titled “Vite Module vs. Manual Asset Helpers”| Capability | Manual manifest.json Reader |
ProcessWire Vite Module |
|---|---|---|
| Dev HMR vs. production switching | Manual if ($config->debug) checks that break on staging |
Automatic hot file detection with instant fallback to production manifest |
| Vite 4 vs. Vite 5+ manifest paths | Hardcoded to one path; breaks on Vite upgrades | Automatically checks {buildDirectory}/{manifest} and {buildDirectory}/.vite/{manifest} |
Transitive chunk CSS & modulepreload |
Often misses CSS imported by nested JS chunks | Recursively traverses imports and css graphs with cycle protection ($visitedImports) |
| Optional per-template bundles | Throws fatal errors when a template-specific file does not exist | Prefix any entry with @ (e.g., @templates/home.ts) to silently skip missing entries |
| Multi-build / module isolation | Global static variables collide across frontend and admin | copy() creates isolated instances with independent buildDirectory, hotFile, and rootUrl |
| CSP nonces & SRI integrity | Hand-rolled string concatenation prone to attribute escaping bugs | First-class useNonce(), useIntegrity(), and custom attribute callbacks with htmlspecialchars escaping |
When to Use Vite
Section titled “When to Use Vite”- Template-driven ProcessWire sites: Bundle Tailwind CSS, TypeScript, Alpine, or HTMX enhancements for
site/templates/with instant dev reload. - Multi-entry sites: Load a shared
app.tsplus optional@templates/{$page->template->name}.tsbundles only on templates that need them. - ProcessWire module development: Serve isolated module bundles alongside the site frontend via
vite()->copy()->useBuildDirectory(...). - Inertia & React stacks:
ProcessWire\Inertiadepends directly onViteto resolve client entrypoints cleanly across dev and production.