ziggy:generate Artisan command to generate JavaScript files containing your route configuration. This is useful for JavaScript frameworks and SPAs that don’t use Blade templates.
ziggy:generate
Generate a JavaScript file containing Ziggy’s routes and configuration.Command Signature
Arguments
Path to the generated JavaScript file.Default: If you provide a directory path, Ziggy will create a
resources/js/ziggy.js (or from config/ziggy.php)ziggy.js file inside it.Options
Generate a TypeScript declaration file with route name and parameter types.Default location: When set to
resources/js/ziggy.d.ts (or {name}.d.ts based on the path argument)false (the default), no TypeScript file is generated.Generate only the TypeScript declaration file, skip the JavaScript file.Useful when you’re only updating type definitions without changing the route configuration.
Override the base URL for generated routes.By default, uses your application’s configured URL.
Filter routes by group name (defined in
config/ziggy.php).Include only routes matching the given patterns (comma-separated).Cannot be used together with
--except.Exclude routes matching the given patterns (comma-separated).Cannot be used together with
--only.Generated Output
JavaScript File
The generated JavaScript file exports aZiggy configuration object:
TypeScript Declarations
With--types, Ziggy generates TypeScript definitions for route names and parameters:
Usage Examples
Basic Generation
With TypeScript
Custom Paths
Route Filtering
CI/CD Integration
Importing the Generated File
After generating the file, import it in your JavaScript:Vue Setup
React Setup
Auto-regeneration
You can set up automatic regeneration when route files change. Here’s an example using a Vite plugin:For more sophisticated watch setups, consider packages like vite-plugin-ziggy.
Configuration
Set default paths inconfig/ziggy.php:
Related
Configuration
Configure default paths and filtering options
Ziggy Class
Learn about the Ziggy class used by this command