Readytocode
  • Home
  • Laravel
  • PHP
  • React Js
  • Git
  • Server
Facebook X (Twitter) Instagram
Readytocode
  • Home
  • Laravel
  • PHP
  • React Js
  • Git
  • Server
Facebook X (Twitter) Instagram Pinterest LinkedIn Reddit
Readytocode
You are at:Home Install Tailwind CSS 3 in Laravel 9 With Vite 3

Laravel

Install Tailwind CSS 3 in Laravel 9 With Vite 3

JustinBy JustinSeptember 26, 2022No Comments3 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email




In this post i will show, how to install Tailwind CSS 3 in Laravel 9.

I will do this in steps wise:

  • Install Laravel Project
  • Setup Tailwind CSS
  • Add Tailwind CSS to app.css
  • Import Vite Assets to Laravel Blade
  • Run Vite Development Server

 

Step 1. Install Laravel Project

Install Laravel 9 using the below command.

composer create-project laravel/laravel TailwindCSSExample;

Step 2: Setup Tailwind CSS

In this step, I will install Tailwind CSS and It’s dependency.

Tailwind CSS Dependency

  1. PostCSS
  2. auto-prefixer

We will install using below command.

First install Tailwind CSS.

npm install -D tailwindcss

Install the dependency.

npm install -D postcss autoprefixer

Now i have to generate Tailwind and post CSS configuration file. Will do using the below command.

npx tailwindcss init -p

The above command will create two configuration file.

tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

Now in this file , we do some change for Laravel blade file. Like below code.

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./resources/**/*.blade.php",
    "./resources/**/*.js",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

 

postcss.config.js

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

 

Step 3: Add Tailwind CSS to app.css

Now add the below line in app/resources/css/app.css

@tailwind base;
@tailwind components;
@tailwind utilities;

now remove ‘resources/css/app.css‘, from vite.config.js. Now vite.config.js is look like below code.

vite.config.js

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

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/js/app.js'
            ],
            refresh: true,
        }),
    ],
});

Now i will do some change in resources/js/app.js , this changes will use for importing css via Javascript.

Add import ‘../css/app.css’ this to resources/js/app.js. And this file will looks like below.

resources/js/app.js

import './bootstrap';
import '../css/app.css'

 

Step 4: Import Vite Assets to Laravel Blade

I will change resources/views/welcome.blade.php , this is already in your project, You can also create a new blade.

<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

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

        <title>Install Tailwind CSS 3 in Laravel 9 With Vite 3</title>

        @vite('resources/js/app.js')
    </head>

    <body class="antialiased">
        <div class="flex justify-center items-center h-screen">
            <h1 class="text-3xl text-purple-600 font-bold">Install Tailwind CSS 3 in Laravel 9 With Vite 3</h1>
        </div>
    </body>

</html>

 

Step 5: Run Vite Development Server

Run the below command to start the Vite Development server.

npm run dev

 

Step 6: Run Laravel Development Server

php artisan serve

 

Now all done. Happy Coding..

 

We are Recommending you

Increase Session Timeout Limit in Laravel9

Laravel9: Add Text or Image Watermark

Laravel 9- Crop Image and Upload to S3

Summernote Editor With Image Upload in Laravel

Laravel 9 send mail using SMTP

How to Export data in Excel and CSV

404 Not Found The requested URL was not found on this server

Laravel 9 Upload Zip and Extract on server

Redirect Laravel app to HTTPS

Laravel 9 – How to Get User Country, City, ZIP from IP

Laravel 9 : Deploy a project on Amazon AWS

 

Total
0
Shares
Share 0
Tweet 0
Pin it 0
Share 0

Like this:

Like Loading...

Related

Install Tailwind CSS 3 Install Tailwind CSS 3 in Laravel 9 With Vite 3 Laravel 9
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Justin
  • Website

Related Posts

How to Generate image from text with Laravel 10

May 16, 2023

Laravel 10 Restrict User Access

May 3, 2023

Laravel 10 Pagination Example

May 3, 2023

Leave A Reply Cancel Reply

Featured Posts
  • Why meta tag is important for seo 1
    How to change react Page title, Page Description and some other meta Tag
    • August 4, 2023
  • 2
    How to Generate image from text with Laravel 10
    • May 16, 2023
  • Laravel 10 Restrict User Access 3
    Laravel 10 Restrict User Access
    • May 3, 2023
  • Laravel 10 Pagination Example 4
    Laravel 10 Pagination Example
    • May 3, 2023
  • install Steam on Ubuntu 5
    How to install Steam on Ubuntu 22.04 step by step
    • April 20, 2023



Readytocode
Facebook X (Twitter) Instagram Pinterest
  • About Us
  • Privacy Policy
© 2025 ReadyToCode.

Type above and press Enter to search. Press Esc to cancel.

%d