git clone https://github.com/lotrando/laravel-inertia-vue-tailwind-webpack.git
composer create-project laravel/laravel:9 laravel-inertia-vue-webpack
composer require inertiajs/inertia-laravel
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="{{ mix('css/app.css') }}" rel="stylesheet">
<script src="{{ mix('js/app.js') }}" defer></script>
</head>
<body class="bg-slate-600 text-gray-400">
@inertia
</body>
</html>
php artisan inertia:middleware
...
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\HandleInertiaRequests::class,
]
]
...
<template>
<div class="container mx-auto">
<slot />
</div>
</template>
<script setup>
</script>
<style>
</style>
<template>
<Head :title="page.title" />
<section class="h-screen grid content-center">
<div class="flex items-center justify-center">
<div
class="flex flex-col justify-center items-center m-5 bg-slate-800 rounded-lg p-5 shadow-xl hover:bg-gradient-to-tr from-slate-800 to-slate-700"
>
<h1 class="font-inter text-2xl text-amber-400 font-bold block">
<Link class="hover:text-amber-300" href="/">
{{ page.title }}
</Link>
</h1>
<p>
{{ page.subtitle }}
</p>
</div>
</div>
</section>
</template>
<script setup>
defineProps({
page: Object,
});
</script>
<style>
</style>
<?php
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
Route::get('/', function () {
sleep(1); // Inertia Progressbar - Test delay;
$page = [
'title' => 'Welcome page',
'description' => 'Welcome.vue file in persistent Layout as slot'
];
return Inertia::render('Welcome', ['page' => $page]);
});
npm install @inertiajs/vue3 vue@latest
import { createApp, h } from 'vue'
import { createInertiaApp, Head, Link } from '@inertiajs/vue3'
import Layout from './Shared/Layout.vue'
createInertiaApp({
resolve: name => {
const page = require(`./Pages/${name}`).default;
page.layout = page.layout || Layout;
return page;
},
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
.component('Head', Head)
.component('Link', Link)
.mount(el)
},
progress: {
color: 'rgb(251, 191, 36)',
includeCSS: true,
showSpinner: true
},
})
npm install --save-dev tailwindcss postcss autoprefixer
npx tailwindcss init -p
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.vue",
],
theme: {
extend: {
fontFamily: {
inter: ['Inter', 'sans-serif'], // font-inter
},
},
},
plugins: [],
}
@tailwind base;
@tailwind components;
@tailwind utilities;
@import 'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap';
const mix = require('laravel-mix');
mix.js('resources/js/app.js', 'public/js')
.vue()
.postCss('resources/css/app.css', 'public/css', [
require('tailwindcss')
])
.sourceMaps()
.version();
npm run dev
or
npm run watch
npm run build
php artisan serve