Skip to content

Commit be7e7a0

Browse files
feat: automatically generate ziggy types with vite
1 parent f1c4c46 commit be7e7a0

File tree

4 files changed

+231
-2
lines changed

4 files changed

+231
-2
lines changed

package-lock.json

Lines changed: 175 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"prettier": "^3.4.2",
2121
"prettier-plugin-organize-imports": "^4.1.0",
2222
"prettier-plugin-tailwindcss": "^0.6.11",
23-
"typescript-eslint": "^8.23.0"
23+
"typescript-eslint": "^8.23.0",
24+
"vite-plugin-run": "^0.6.1"
2425
},
2526
"dependencies": {
2627
"@headlessui/react": "^2.2.0",

resources/js/types/ziggy.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* This file is generated by Ziggy. */
2+
declare module 'ziggy-js' {
3+
interface RouteList {
4+
"home": [],
5+
"dashboard": [],
6+
"profile.edit": [],
7+
"profile.update": [],
8+
"profile.destroy": [],
9+
"password.edit": [],
10+
"password.update": [],
11+
"appearance": [],
12+
"register": [],
13+
"login": [],
14+
"password.request": [],
15+
"password.email": [],
16+
"password.reset": [
17+
{
18+
"name": "token",
19+
"required": true
20+
}
21+
],
22+
"password.store": [],
23+
"verification.notice": [],
24+
"verification.verify": [
25+
{
26+
"name": "id",
27+
"required": true
28+
},
29+
{
30+
"name": "hash",
31+
"required": true
32+
}
33+
],
34+
"verification.send": [],
35+
"password.confirm": [],
36+
"logout": [],
37+
"storage.local": [
38+
{
39+
"name": "path",
40+
"required": true
41+
}
42+
]
43+
}
44+
}
45+
export {};

vite.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import react from '@vitejs/plugin-react';
33
import laravel from 'laravel-vite-plugin';
44
import { resolve } from 'node:path';
55
import { defineConfig } from 'vite';
6+
import { run } from 'vite-plugin-run';
67

78
export default defineConfig({
89
plugins: [
@@ -13,6 +14,14 @@ export default defineConfig({
1314
}),
1415
react(),
1516
tailwindcss(),
17+
run({
18+
input: [
19+
{
20+
run: ['php', 'artisan', 'ziggy:generate', '--types-only', 'resources/js/types/ziggy.d.ts'],
21+
pattern: ['config/ziggy.php', 'routes/**/*.php'],
22+
},
23+
],
24+
}),
1625
],
1726
esbuild: {
1827
jsx: 'automatic',

0 commit comments

Comments
 (0)