Skip to content

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/.

  1. Configure site/templates/vite.config.ts:

    Write a hot file during vite serve and emit .vite/manifest.json during vite 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',
    ],
    },
    },
    });
  2. 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>
  3. Run the Vite dev server for live HMR:

    Terminal window
    npm run dev

    Reload your ProcessWire page. Vite detects site/templates/hot and outputs <script type="module" src="http://localhost:5173/@vite/client"> along with your dev entry scripts.

  4. Build for production:

    Terminal window
    npm run build

    Stop the dev server (which removes hot) and reload. Vite automatically reads site/templates/build/.vite/manifest.json and emits hashed <link rel="stylesheet">, <link rel="modulepreload">, and <script type="module"> tags.

Next steps