Answer of "How to use tailwind css with laravel 10?"
Step 1 : Install tailwindcss and its peer dependencies via npm
npm install -D tailwindcss postcss autoprefixer
Step 2 : run the init command to generate both tailwind.config.js
and postcss.config.js
.
npx tailwindcss init -p
Step 3 : Add the paths to all of your template files in your tailwind.config.js
file.
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./resources/**/*.blade.php", // for blade files
"./resources/**/*.js", // for single page applications
],
theme: {
extend: {},
},
plugins: [],
}
Step 4 : Add the @tailwind
directives for each of Tailwind’s layers to your ./resources/css/app.css
file.
@tailwind base;
@tailwind components;
@tailwind utilities;
Step 5 : Run your build process with npm run dev : This command will start the development server and you can see your changes on the runing laravel web application
npm run dev
Step 6 : Start using Tailwind in your project -
Make sure your compiled CSS is included in the <head>
then start using Tailwind’s utility classes to style your content. resources\views\welcome.blade.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@vite('resources/css/app.css')
</head>
<body>
<h1 class="text-3xl font-bold underline">
Hello world!
</h1>
</body>
</html>
Step 7 : start the laravel server
php artisan serve
Step 8 : Now you can directly see your changes on the web -- There is one last step needed - when you are happy with your changes - commit them
Actually you need to run build for your application which saves the changes - If you don't do this step after completion the chages will not reflect if you stop you npm server
To build your app
npm run build
php artisan cache:clear
php artisan optimize
composer install
⭐️ Star my repository if you find it helpful.