joshcirre/inertiakit

File-based Inertia routing, simplified server controllers + typed models & props

v0.0.10-alpha 2025-04-25 22:39 UTC

This package is auto-updated.

Last update: 2025-04-25 22:50:07 UTC


README

inertiaKIT logo

inertiaKIT (WIP)

inertiaKIT is a zero-boilerplate approach to file-based routing and typed props in Laravel + InertiaJS created by Josh Cirre. It auto-generates:

  • Routes (and optional Controllers) from resources/js/pages/*.server.php
  • TypeScript interfaces for your Eloquent models
  • TypeScript interfaces for your page props, with camelCased keys and model types

⚠️ Alpha software—expect rough edges!

📦 Installation

  1. Require the package

    composer require joshcirre/inertia-kit:^0.0.10-alpha
  2. Install the package

    php artisan inertiakit:install
  3. (Optional but recommended) Install Laravel Wayfinder for zero-config route-action types:

    composer require laravel/wayfinder

⚙️ Configuration

Edit your config/inertiakit.php to tailor:

return [
    // Explicit Eloquent models to type, or empty = auto-discover all under app/Models
    'models'         => [],

    // Where to write your generated TS model interfaces
    'types_output'   => 'resources/js/types/models.d.ts',

    // Generate real Controllers under app/Http/Controllers/Generated
    'use_controllers'=> env('INERTIAKIT_USE_CONTROLLERS', true),

    // Where to dump your auto-generated routes file
    'routes_file'    => 'routes/inertiakit.php',

    // Glob patterns under resources/js/pages to ignore
    'ignore'         => [
        'auth/*',
        'settings/*',
        'welcome',
        'dashboard',
    ],
];

🚀 Usage

Run the generation command manually once php artisan inertiakit:generate, or run the following as needed:

php artisan inertiakit:generate
php artisan inertiakit:model-types
php artisan inertiakit:page-types

🔄 Automatic Re-generation with Vite

For seamless DX, you can hook up a file watcher in your vite.config.js. (this is done automatically when you run inertiakit:install)

npm install -D vite-plugin-run

And in your vite.config.js:

import laravel from 'laravel-vite-plugin';
import { run } from 'vite-plugin-run';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    laravel({
      input: ['resources/css/app.css', 'resources/js/app.tsx'],
      ssr:   'resources/js/ssr.tsx',
      refresh: true,
    }),
    run([
      {
        name: 'inertiakit:types',
        run: ['php', 'artisan', 'inertiakit:model-types && php artisan inertiakit:page-types'],
        pattern: ['app/Models/**/*.php', 'resources/js/pages/**/*.server.php'],
      },
    ]),
  ],
});

📖 Further Reading

Happy coding! 🎉