Skip to content

feat: automatically generate ziggy types with vite #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

SantosVilanculos
Copy link

Feat: Automate Ziggy Type Generation

This pull request introduces a new development dependency, vite-plugin-run, to automatically generate Ziggy type
definitions whenever relevant files are modified. This ensures that TypeScript always has the latest route information,
improving type safety and developer experience.

Key changes:

  • Added vite-plugin-run: This Vite plugin allows running shell commands during development.
  • Configured vite.config.ts: The configuration now automatically executes php artisan ziggy:generate --types-only to
    create resources/js/types/ziggy.d.ts when changes are detected in config/ziggy.php or any file under the routes/
    directory.
  • Generated resources/js/types/ziggy.d.ts: The initial type definition file has been generated and included in this
    pull request.

Benefits:

  • Improved Type Safety: Ensures that the route() helper is always used with correct and up-to-date route names and
    parameters.
  • Enhanced Developer Experience: Provides autocompletion and type hinting for routes in the IDE, reducing the chance of
    typos and errors.
  • Automation: Eliminates the need to manually run the ziggy:generate command, streamlining the development workflow.

Video Demonstration:

untitled.mp4

@taylorotwell
Copy link
Member

We are going to be moving this to Wayfinder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants