Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How to setup laravel + vuejs + inertiajs + tailwindcss

// Create a fresh laravel project
composer create-project laravel/laravel example-app OR laravel new example-app


// install npm dependencies 
npm install


// Install postcss and autoprefixer
npm install -D tailwindcss postcss autoprefixer


// Create tailwind css config file
npx tailwindcss init


// Add ./resources/js/**/*.{vue,js} to the content in the tailwind.config.js file
module.exports = {
    content: ["./resources/js/**/*.{vue,js}"],
    theme: {
        extend: {},
    },
    plugins: [],
};


// Add the Tailwind's directives to resources/css/app.css
@tailwind base;
@tailwind components;
@tailwind utilities;


// require Tailwind into webpack.mix.js
mix.js("resources/js/app.js", "public/js").postCss(
    "resources/css/app.css",
    "public/css",
    [require("tailwindcss")]
);


// Install Vuejs
npm install vue@next


// Install Inertia's server side package
composer require inertiajs/inertia-laravel


// Create the inertia middleware
php artisan inertia:middleware


// Add inertia middleware to the web middleware group inside app/Http/Kernel.php
'web' => [
    // ...
    AppHttpMiddlewareHandleInertiaRequests::class,
],


// Install inertia client side
npm install @inertiajs/inertia @inertiajs/inertia-vue3

// Install inertiajs progressbar (OPTIONAL)
npm install @inertiajs/progress


// Install Ziggy
composer require tightenco/ziggy in laravel


// Setup blade root file for the application
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    @routes
    <link href="{{ asset(mix('css/app.css')) }}" rel="stylesheet">
    <script src="{{ asset(mix('js/manifest.js')) }}" defer></script>
    <script src="{{ asset(mix('js/vendor.js')) }}" defer></script>
    <script src="{{ asset(mix('js/app.js')) }}" defer></script>
    @inertiaHead
</head>

<body>
    @inertia
</body>

</html>


// Setup ziggy
php artisan ziggy:generate resources/js/ziggy.js


// Add to resolve ziggy in vue
const path = require("path");

// Rezolve Ziggy
mix.alias({
    ziggy: path.resolve("vendor/tightenco/ziggy/dist/vue"),
});


// Setup resources/js/app.js
import { createApp, h } from "vue";
import { createInertiaApp, Link, Head } from "@inertiajs/inertia-vue3";
import { InertiaProgress } from "@inertiajs/progress";

import { ZiggyVue } from "ziggy";
import { Ziggy } from "./ziggy";

InertiaProgress.init();

createInertiaApp({
    resolve: async (name) => {
        return (await import(`./Pages/${name}`)).default;
    },
    setup({ el, App, props, plugin }) {
        createApp({ render: () => h(App, props) })
            .use(plugin)
            .use(ZiggyVue, Ziggy)
            .component("Link", Link)
            .component("Head", Head)
            .mixin({ methods: { route } })
            .mount(el);
    },
});


// Your final webpack.mix.js file
const path = require("path");
const mix = require("laravel-mix");

// Rezolve Ziggy
mix.alias({
    ziggy: path.resolve("vendor/tightenco/ziggy/dist/vue"),
});

// Build files
mix.js("resources/js/app.js", "public/js")
    .vue({ version: 3 })
    .webpackConfig({
        resolve: {
            alias: {
                "@": path.resolve(__dirname, "resources/js"),
            },
        },
    })
    .extract()
    .postCss("resources/css/app.css", "public/css", [require("tailwindcss")])
    .version();
    
    
    
// Setup laravel routes in web.php
Route::get(
    '/',
    function () {
        return Inertia::render(
            'Home',
            [
                'title' => 'Homepage',
            ]
        );
    }
)->name( 'homepage' );


// Create links in your vue files
<Link :href="route('homepage')" 
	class="text-gray-700 bg-gray-200 hover:bg-gray-700 hover:text-white px-3 py-2 rounded-md text-sm font-medium">
Homepage
</Link>
Comment

configuring tailwindcss, vue and laravel

const mix = require("laravel-mix");

mix.js("resources/js/app.js", "public/js")
    .vue()
    .postCss("resources/css/app.css", "public/css", [require("tailwindcss")]);
Comment

PREVIOUS NEXT
Code Example
Python :: foreach loop in python 
Python :: python ON DUPLICATE KEY UPDATE 
Python :: pandas filter by dictionary 
Python :: keras model 2 outputs 
Python :: python date time 
Python :: .replace python 
Python :: filter in python 
Python :: can list hold different data types in python 
Python :: iterrows pandas 
Python :: pandas dataframe check for values more then a number 
Python :: dataframe column condition in list 
Python :: convert image to binary python 
Python :: remove figure label 
Python :: operator.itemgetter(1) in python 
Python :: elbow plot for k means clustering 
Python :: how to check if all values in list are equal python 
Python :: decimal to binary 
Python :: extract directory python 
Python :: how to convert string into list in python 
Python :: python match case 
Python :: python loop array 
Python :: delete from table django 
Python :: generate python 
Python :: sort a list python 
Python :: How to Remove Items in a Set in Python Using the discard() Method 
Python :: Implement a binary search of a sorted array of integers Using pseudo-code. 
Python :: python replace list from another dictionary items 
Python :: stemming words python 
Python :: plt.hist bins 
Python :: python write float with 2 decimals 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =