{"id":22938,"library":"vite-plugin-ziggy","title":"vite-plugin-ziggy","description":"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.","status":"active","version":"0.3.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","vite","vite-plugin","ziggy","typescript"],"install":[{"cmd":"npm install vite-plugin-ziggy","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-ziggy","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-ziggy","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Vite plugin, requires Vite as peer dependency","package":"vite","optional":false}],"imports":[{"note":"Default export; ESM-only usage recommended in Vite config files. CommonJS require works in CJS contexts, but Vite configs are typically ESM.","wrong":"const ziggy = require('vite-plugin-ziggy');","symbol":"default (ziggy)","correct":"import ziggy from 'vite-plugin-ziggy';"},{"note":"Add to tsconfig.json types array, not import statement. This references the generated type declaration file at node_modules/vite-plugin-ziggy/routes.","wrong":"import './node_modules/vite-plugin-ziggy/routes';","symbol":"type declaration","correct":"// In tsconfig.json types: [\"vite-plugin-ziggy/routes\"]"},{"note":"ZiggyRoute is declared globally in the generated types file. Do not import from the package directly.","wrong":"import { ZiggyRoute } from 'vite-plugin-ziggy';","symbol":"ZiggyRoute type","correct":"// Generated type is available globally as ZiggyRoute"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport ziggy from 'vite-plugin-ziggy';\n\nexport default defineConfig({\n  plugins: [\n    ziggy({\n      sail: true,\n      group: 'api',\n      url: process.env.APP_URL ?? 'http://localhost',\n      only: ['admin.*'],\n      except: ['debugbar.*'],\n      types: true,\n      typesOnly: false,\n    }),\n  ],\n});\n\n// tsconfig.json\n{\n  \"compilerOptions\": {\n    \"types\": [\"vite/client\", \"vite-plugin-ziggy/routes\"]\n  }\n}\n\n// After running vite, route types are auto-generated.\n// Use in any TS file:\nconst routeName: ZiggyRoute = 'admin.users.index';\nroute(routeName, { id: 1 }); // typed parameters","lang":"typescript","description":"Shows minimal Vite plugin setup with common options and tsconfig type inclusion for generated route types."},"warnings":[{"fix":"Add node_modules/vite-plugin-ziggy/routes.d.ts to .gitignore.","message":"Generated types file is placed in node_modules; ensure it's not committed to version control.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Rename global type using plugin config or avoid duplicate global names.","message":"ZiggyRoute type is declared globally; conflicts with other packages using same global name may occur.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set custom path in plugin configuration to prepare for migration.","message":"v1.0.0 will change default output path from node_modules/vite-plugin-ziggy/routes to a project-level location.","severity":"breaking","affected_versions":">=0.0.0 <1.0.0"},{"fix":"Explicitly set typesOnly: false if you need both types and route data.","message":"Option 'typesOnly' defaults to true but in v0.4.0 will default to false to generate both types and actual route data.","severity":"deprecated","affected_versions":"==0.3.0"},{"fix":"Ensure 'php artisan' or 'sail' is available in PATH.","message":"Requires Laravel project with artisan route:list command accessible. Sail option uses 'sail' shell command.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add \"vite-plugin-ziggy/routes\" to the 'types' array in tsconfig.json.","cause":"TypeScript cannot locate generated type declaration because tsconfig.json 'types' array is missing.","error":"Cannot find module 'vite-plugin-ziggy/routes' or its corresponding type declarations."},{"fix":"Use default import: import ziggy from 'vite-plugin-ziggy';","cause":"Incorrect import style: using named export instead of default export.","error":"TypeError: ziggy is not a function"},{"fix":"Disable sail: false or install Laravel Sail.","cause":"Sail option enabled but Laravel Sail is not installed or not in PATH.","error":"The term 'sail' is not recognized as the name of a cmdlet, function, script file, or operable program."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}