Skip to main content
Ziggy provides the 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

string
Path to the generated JavaScript file.Default: resources/js/ziggy.js (or from config/ziggy.php)
If you provide a directory path, Ziggy will create a ziggy.js file inside it.

Options

string
default:"false"
Generate a TypeScript declaration file with route name and parameter types.Default location: resources/js/ziggy.d.ts (or {name}.d.ts based on the path argument)
When set to false (the default), no TypeScript file is generated.
boolean
Generate only the TypeScript declaration file, skip the JavaScript file.
Useful when you’re only updating type definitions without changing the route configuration.
string
Override the base URL for generated routes.
By default, uses your application’s configured URL.
string
Filter routes by group name (defined in config/ziggy.php).
string
Include only routes matching the given patterns (comma-separated).
Cannot be used together with --except.
string
Exclude routes matching the given patterns (comma-separated).
Cannot be used together with --only.

Generated Output

JavaScript File

The generated JavaScript file exports a Ziggy configuration object:

TypeScript Declarations

With --types, Ziggy generates TypeScript definitions for route names and parameters:
This enables full autocompletion in editors like VS Code:

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 in config/ziggy.php:

Configuration

Configure default paths and filtering options

Ziggy Class

Learn about the Ziggy class used by this command