Ziggy Vite Plugin

February 5, 2025 · View on GitHub

Vite plugin for generating Ziggy route types automatically when your route files change

npm i -D vite-plugin-ziggy

Usage

After you installed vite-plugin-ziggy add it to your Vite configuration like so:

import { defineConfig } from 'vite';
...
import ziggy from 'vite-plugin-ziggy';

export default defineConfig({
  plugins: [
    ...
    ziggy({
      sail: true, // Uses Sail instead of PHP
      group: 'api',
      url: 'http://laravel-app.test',
      only: ['admin.*'],
      except: ['debugbar.*'],
    }),
  ],
});

Then just add the types to tsconfig.json:

{
    "compilerOptions": {
        ...,
        "types": [
            "vite/client",
            "vite-plugin-ziggy/routes"
        ]
    }
}

After that, every time you make a change to any routes in routes/ This plugin will auto generate your route types for Ziggy's route() to auto complete for you.

Configuration

This plugin allows you to set the following configuration:

KeyDescriptionRequiredDefault
pathThe path to output the types file❌ Nonode_modules/vite-plugin-ziggy/routes
onlyInclude ONLY these routes❌ No[]
exceptAll routes EXCEPT these❌ No[]
sailUse sail instead of the php command❌ Nofalse
groupRoute group to generate❌ Noundefined (not set by default)
urlThe application URL❌ Noundefined (not set by default)
typesGenerate TypeScript declaration file❌ Notrue
typesOnlyGenerate only the TypeScript declaration file❌ Notrue