Registry / web-framework / vite-plugin-ziggy

vite-plugin-ziggy

JSON →
library0.3.0jsnpmunverified

Vite plugin that auto-generates TypeScript route type definitions for Laravel Ziggy based on your Laravel route files. Current stable version is 0.3.0, released with a focus on seamless integration with Laravel development workflows. Key differentiators: automatic regeneration on route file changes, support for Sail, route filtering (only/except), and optional sail/php execution. Alternatives require manual type generation or separate build steps.

npm install vite-plugin-ziggy
INSTALL
IMPORT
SIG · VITE-PLUGIN-ZIGGY
V
vite-plugin-ziggy
web-frameworkjavascriptv0.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (ziggy)
import ziggy from 'vite-plugin-ziggy';
const ziggy = require('vite-plugin-ziggy');
Default export; ESM-only usage recommended in Vite config files. CommonJS require works in CJS contexts, but Vite configs are typically ESM.
type declaration
// In tsconfig.json types: ["vite-plugin-ziggy/routes"]
import './node_modules/vite-plugin-ziggy/routes';
Add to tsconfig.json types array, not import statement. This references the generated type declaration file at node_modules/vite-plugin-ziggy/routes.
ZiggyRoute type
// Generated type is available globally as ZiggyRoute
import { ZiggyRoute } from 'vite-plugin-ziggy';
ZiggyRoute is declared globally in the generated types file. Do not import from the package directly.

Shows minimal Vite plugin setup with common options and tsconfig type inclusion for generated route types.

// vite.config.ts import { defineConfig } from 'vite'; import ziggy from 'vite-plugin-ziggy'; export default defineConfig({ plugins: [ ziggy({ sail: true, group: 'api', url: process.env.APP_URL ?? 'http://localhost', only: ['admin.*'], except: ['debugbar.*'], types: true, typesOnly: false, }), ], }); // tsconfig.json { "compilerOptions": { "types": ["vite/client", "vite-plugin-ziggy/routes"] } } // After running vite, route types are auto-generated. // Use in any TS file: const routeName: ZiggyRoute = 'admin.users.index'; route(routeName, { id: 1 }); // typed parameters
Debug
Known issues
gotchaGenerated types file is placed in node_modules; ensure it's not committed to version control.
fix
Add node_modules/vite-plugin-ziggy/routes.d.ts to .gitignore.
affects: >=0.0.0
gotchaZiggyRoute type is declared globally; conflicts with other packages using same global name may occur.
fix
Rename global type using plugin config or avoid duplicate global names.
affects: >=0.0.0
breakingv1.0.0 will change default output path from node_modules/vite-plugin-ziggy/routes to a project-level location.
fix
Set custom path in plugin configuration to prepare for migration.
affects: >=0.0.0 <1.0.0
deprecatedOption 'typesOnly' defaults to true but in v0.4.0 will default to false to generate both types and actual route data.
fix
Explicitly set typesOnly: false if you need both types and route data.
affects: ==0.3.0
gotchaRequires Laravel project with artisan route:list command accessible. Sail option uses 'sail' shell command.
fix
Ensure 'php artisan' or 'sail' is available in PATH.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'vite-plugin-ziggy/routes' or its corresponding type declarations.
TypeScript cannot locate generated type declaration because tsconfig.json 'types' array is missing.
fix
Add "vite-plugin-ziggy/routes" to the 'types' array in tsconfig.json.
TypeError: ziggy is not a function
Incorrect import style: using named export instead of default export.
fix
Use default import: import ziggy from 'vite-plugin-ziggy';
The term 'sail' is not recognized as the name of a cmdlet, function, script file, or operable program.
Sail option enabled but Laravel Sail is not installed or not in PATH.
fix
Disable sail: false or install Laravel Sail.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
viterequiredVite plugin, requires Vite as peer dependency
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
vite-plugin-ziggy — npm install vite-plugin-ziggy · libregistry