Installation
Install Tailwind CSS with AdonisJS
Setting up Tailwind CSS in an AdonisJS project.
Create your project
Start by creating a new AdonisJS project if you don’t have one set up already. The most common approach is to use Create AdonisJS.
Terminalnpm init adonisjs@latest my-project -- --kit=webcd my-project
Install Tailwind CSS
Install
tailwindcss
and its peer dependencies, then generate yourtailwind.config.js
andpostcss.config.js
files.Terminalnpm install -D tailwindcss postcss autoprefixernpx tailwindcss init -p
Configure your template paths
Add the paths to all of your template files in your
tailwind.config.js
file.
Add Inertia path if you are using Inertia.js.tailwind.config.js/** @type {import('tailwindcss').Config} */ export default { content: [ "./resources/**/*.edge", "./resources/**/*.{js,ts,jsx,tsx,vue}", // If you are using Inertia.js "./inertia/**/*.{js,ts,jsx,tsx,vue}", ], theme: { extend: {}, }, plugins: [], }
Add the Tailwind directives to your CSS
Add the
@tailwind
directives for each of Tailwind’s layers to your./resources/css/app.css
or./inertia/css/app.css
file, depending on Edge or Inertia.js.app.css@tailwind base; @tailwind components; @tailwind utilities;
For Inertia, remove Tailwind CDN from your layout
If you're using Inertia, make sure to remove the Tailwind CDN in the
./resources/views/inertia_layout.edge
to avoid duplicate Tailwind imports.inertia_layout.edge<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title inertia>AdonisJS x Inertia x React</title> <link rel="preconnect" href="https://fonts.bunny.net"> <link href="https://fonts.bunny.net/css?family=instrument-sans:400,400i,500,500i,600,600i,700,700i" rel="stylesheet" /> <style> :root { --sand-1: #fdfdfc; --sand-2: #f9f9f8; --sand-3: #f1f0ef; --sand-4: #e9e8e6; --sand-5: #e2e1de; --sand-6: #dad9d6; --sand-7: #cfceca; --sand-8: #bcbbb5; --sand-9: #8d8d86; --sand-10: #82827c; --sand-11: #63635e; --sand-12: #21201c; } </style> <script src="https://cdn.tailwindcss.com"></script> <script> tailwind.config = { theme: { extend: { fontFamily: { sans: ['Instrument Sans', 'sans-serif'], }, colors: { primary: { DEFAULT: '#5A45FF', }, sand: { 1: 'var(--sand-1)', 2: 'var(--sand-2)', 3: 'var(--sand-3)', 4: 'var(--sand-4)', 5: 'var(--sand-5)', 6: 'var(--sand-6)', 7: 'var(--sand-7)', 8: 'var(--sand-8)', 9: 'v and import it herear(--sand-9)', 10: 'var(--sand-10)', 11: 'var(--sand-11)', 12: 'var(--sand-12)', }, }, }, }, } </script> @viteReactRefresh() @inertiaHead() @vite(['inertia/app/app.tsx', `inertia/pages/${page.component}.tsx`]) </head> <body class="min-h-screen w-screen font-sans"> @inertia() </body> </html>
Start your build process
Run your build process with
npm run dev
.Terminalnpm run dev
Start using Tailwind in your project
If you're using Edge, make sure your compiled CSS is included in the
<head>
then start using Tailwind’s utility classes to style your content.home.edge<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Only when using Edge --> @vite(['resources/css/app.css', 'resources/js/app.js']) </head> <body> <h1 class="text-3xl font-bold underline"> Hello world! </h1> </body> </html>