5-Minute Quickstart
This quickstart wires the Aegean Voyages (aegeanvoyages.example) charter frontend in site/templates/ to ProcessWire\Vite using the real-world files in site/modules/Vite/examples/real-world/.
End-to-End Setup
Section titled “End-to-End Setup”-
Configure
site/templates/vite.config.ts:Write a
hotfile duringvite serveand emit.vite/manifest.jsonduringvite build:import fs from 'node:fs';import path from 'node:path';import { defineConfig, type Plugin } from 'vite';function hotFilePlugin(hotFilePath: string): Plugin {return {name: 'processwire-hot-file',configureServer(server) {server.httpServer?.once('listening', () => {const address = server.httpServer?.address();const port = typeof address === 'object' && address ? address.port : 5173;fs.writeFileSync(hotFilePath, `http://localhost:${port}`);});const cleanup = () => {if (fs.existsSync(hotFilePath)) fs.unlinkSync(hotFilePath);};process.on('exit', cleanup);process.on('SIGINT', () => { cleanup(); process.exit(); });},};}export default defineConfig({base: '/site/templates/build/',plugins: [hotFilePlugin(path.resolve(__dirname, 'hot'))],build: {outDir: 'build',manifest: true,rollupOptions: {input: ['resources/css/app.css','resources/ts/app.ts','resources/ts/templates/yacht.ts',],},},}); -
Render Vite tags in your template
<head>(site/templates/_main.php):Use
vite()(or$this->wire()->vite) with optional@per-template bundles:<?php namespace ProcessWire; ?><!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title><?= $sanitizer->entities($page->title) ?></title><?= vite(['resources/css/app.css','resources/ts/app.ts',"@resources/ts/templates/{$page->template->name}.ts",]) ?></head><body><?= $content ?></body></html> -
Run the Vite dev server for live HMR:
Terminal window npm run devReload your ProcessWire page.
Vitedetectssite/templates/hotand outputs<script type="module" src="http://localhost:5173/@vite/client">along with your dev entry scripts. -
Build for production:
Terminal window npm run buildStop the dev server (which removes
hot) and reload.Viteautomatically readssite/templates/build/.vite/manifest.jsonand emits hashed<link rel="stylesheet">,<link rel="modulepreload">, and<script type="module">tags.