laravel/svelte-starter-kit
Modern Laravel starter kit with a Svelte 5 + TypeScript frontend powered by Inertia. Includes Tailwind, shadcn-svelte, and bits-ui for UI, plus fast Vite builds. Ideal for building SPA-like apps with classic Laravel routing and controllers.
Installation:
composer create-project laravel/svelte-starter-kit my-app
cd my-app
npm install
npm run dev
vite.config.js or inertia.config.js tweaks are needed for basic use.First Use Case:
/resources/js/Pages/Welcome.svelte and modify the <h1> tag to test reactivity.php artisan serve and visit http://localhost:8000. Changes reflect instantly due to Vite’s HMR.Key Directories:
resources/js/Pages/ (Svelte components), resources/js/Layouts/ (shared layouts).app/Http/Controllers/ (Inertia controllers), routes/web.php (server-side routes).vite.config.ts (Vite settings), inertia.config.ts (Inertia presets).Server-Side Routing:
routes/web.php with Inertia::render():
Route::get('/dashboard', [DashboardController::class, 'index']);
Data Fetching:
Inertia::render():
public function index()
{
return Inertia::render('Dashboard', [
'users' => User::all(),
]);
}
<script lang="ts">
export let users: User[];
</script>
State Management:
import { writable } from 'svelte/store').page.props for shared data (e.g., auth user):
<script lang="ts">
import { page } from '@inertiajs/svelte';
</script>
<p>Welcome, {page.props.auth.user.name}</p>
Forms:
useForm from @inertiajs/svelte for CSRF protection and server-side validation:
<script lang="ts">
import { useForm } from '@inertiajs/svelte';
const form = useForm({
email: '',
password: '',
});
</script>
<form method="POST" on:submit|preventDefault={form.submit('login')}>
<input type="email" bind:value={form.data.email} />
</form>
Component Libraries:
npx shadcn-svelte@latest add button).<Dropdown />) directly in Svelte files.API Calls:
axios (included) with Inertia’s visit for SPA-like navigation:
<script lang="ts">
import { router } from '@inertiajs/svelte';
async function fetchData() {
const response = await axios.get('/api/data');
router.visit('/dashboard', { data: response.data });
}
</script>
Authentication:
app/Http/Middleware/HandleInertiaRequests.php to customize share props (e.g., auth user).TypeScript Strictness:
export let for props in Svelte components.page.props (e.g., page.props.auth should be typed as Auth).npm run typecheck to catch errors early.Vite HMR Delays:
+page.svelte for lazy-loaded routes.Inertia Page Loading:
onMount of root layouts. Use page.props for initial data and lazy-load additional content.shadcn-svelte Quirks:
import { Button } from '@/components/ui/button').@/components/ui to tsconfig.json paths for cleaner imports.Tailwind JIT Conflicts:
tailwind.config.js may break if not merged properly. Use @tailwindcss/forms for default styles.CSRF Token:
@csrf directive in forms causes 419 errors. Use useForm or @inertiajs/svelte helpers to auto-include it.Inertia Errors:
Inertia errors. Common causes:
routes/web.php and Svelte’s Link components.method in form submissions (e.g., form.submit('POST', '/route')).Vite Dev Server:
node_modules/.vite and restart npm run dev.Laravel Logs:
APP_DEBUG=true in .env for detailed error messages.Custom Inertia Layouts:
resources/js/Layouts/AppLayout.svelte for shared headers/footers. Override in child components:
<AppLayout title="Custom Title">
<slot />
</AppLayout>
API Routes:
Route::prefix('api')->middleware('auth:sanctum') in routes/api.php for SPAs. Protect Svelte routes with middleware('auth').Testing:
@inertiajs/svelte/testing for component tests:
import { render } from '@testing-library/svelte';
import { screen } from '@testing-library/svelte';
render(<Welcome />);
expect(screen.getByText('Welcome')).toBeInTheDocument();
Production Builds:
npm run build to generate optimized assets in public/build. Configure Laravel’s mix-manifest.json for asset versioning:
// app/Http/Middleware/TrustProxies.php
$app->use(TrustProxies::class)->only('web');
Monorepo Support:
npm link or Vite’s build.rollupOptions.input for modular imports.resources/js/features/Auth/Login.svelte).zod for runtime validation in Svelte:
<script lang="ts">
import { z } from 'zod';
const schema = z.object({ email: z.string().email() });
const form = useForm({ email: '' }, { schema });
</script>
inertia.config.ts for SEO-critical pages:
export default defineInertiaConfig({
serverSideRendering: true,
});
bits-ui’s <Theme> component or Tailwind’s dark: classes with data-theme attributes.
How can I help you explore Laravel packages today?