Instal Tailwind CSS di Laravel

Laravel Hosting
Prerequisites
Step 1: Navigate to your Laravel Project Directory
Start by navigating to your Laravel project’s directory.
If you don’t have a project set up already, you can use Composer or Softaculous to install Laravel.
Step 2: Install Tailwind CSS
Now install Tailwind CSS through npm. Open your terminal, navigate to your Laravel project directory, and run the following command:
npm install tailwindcss@latest postcss@latest autoprefixer@latest
This command installs Tailwind CSS along with PostCSS and Autoprefixer, which are necessary for processing Tailwind’s CSS file.
Step 3: Create Tailwind Config File
Generate a Tailwind configuration file by executing:
This command creates a tailwind.config.js
and a postcss.config.js
file in your project root. You can customize this configuration file to tailor Tailwind’s setup to your project’s needs.
/** @typeimport('tailwindcss').Config */
module.exports=
content: [],
theme:
extend: ,
,
plugins: [],
module.exports=
plugins:
tailwindcss: ,
autoprefixer: ,
,
Step 4: Configure Tailwind to Process Your CSS
Create a CSS file in your ./resources/css
directory, for example, app.css
, and add the Tailwind directives to it:
@tailwind base;
@tailwind components;
@tailwind utilities;
Step 5: Start the Build Process
Run the following command to compile your CSS and JS files including Tailwind CSS.
Or, for production, use:
This command minimizes the CSS, optimizing it for production use.
Step 6: Start Using Tailwind CSS
Add the compiled CSS to the <head>
of your view using @vite
to import the app.css
file.
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
@vite('resources/css/app.css')
<title>Test View</title>
</head>
You can now start using Tailwind utility classes to style your application.
<!DOCTYPEhtml>
<htmllang="en">
<head>
<metacharset="UTF-8">
<metaname="viewport"content="width=device-width, initial-scale=1.0">
@vite('resources/css/app.css')
<title>Test View</title>
</head>
<body>
<h1class="mb-6 text-5xl font-bold">
Hello world!
</h1>
</body>
</html>
Conclusion
You’ve successfully integrated Tailwind CSS into your Laravel project. You can now use Tailwind’s utility classes to style your application directly within your views, speeding up development and ensuring a consistent design system.
Remember, you can customize your tailwind.config.js
file to extend or modify Tailwind’s default configuration, tailoring it to your project’s specific needs.
Happy styling with Tailwind CSS and Laravel!
Comments
Post a Comment