Setting up TailwindCSS in a Laravel project

I enjoy web development, creating unique projects, and devouring books. Follow me on my dev journey!
Search for a command to run...

I enjoy web development, creating unique projects, and devouring books. Follow me on my dev journey!
No comments yet. Be the first to comment.
There are so many free resources available online to help you start (and continue) your journey in web development. In this post, I've gathered a list of my favorite, and most high-quality, materials. If you have additional suggestions on resources...

If you're exploring the world of web development, chances are you've created your own sites that you want to put out there for the world to see. Hosting your own website for free has gotten easier than ever before. As a developer, you have several o...

There's a lot that goes into becoming a better programmer, so let's just tackle one way that helps improve your programming skills today: practice, practice, practice solving problems. 😤 Practice Makes Perfect Mastering any skill takes time, and co...

Let's get started! Creating an EmberJS project See https://guides.emberjs.com/release/getting-started/quick-start/ for more information. If you haven't already, you can install the Ember CLI using the following command: npm install -g ember-cli Then...

GOAL: Create a weekly calendar app where one can plan and schedule tasks. Integrations with Google Calendar and task apps. Note: I will be using Astro.build, but the basic concepts of this tutorial should work with any other setup (Vite, CRA, etc.). ...

Make sure Composer and npm are installed before you begin! (Note: If you prefer using SASS or LESS, the below tutorial may not be applicable.)
If you haven't set up Laravel yet, follow the steps below. Otherwise, skip these two steps.
Run composer global require laravel/installer
From command line, cd into the directory you want to install Laravel in and run laravel new myProjectName. A folder titled myProjectName will be created with Laravel installed in it.
Navigate to your project's root folder (cd myProjectName) and run:
npm install
npm install tailwindcss
Then run:
cd resources
mkdir css
The above commands will create a folder named css in resources.
In resources/css, create a file named tw.css (or whatever name you prefer - just be sure to substitute your file's name for tw.css in this tutorial). This file will contain your uncompiled Tailwind CSS. Here, you can add @tailwind base;, @tailwind components;, @tailwind utilities;, etc.
Next, navigate to webpack.config.js in your project's root folder. Add the following code snippet:
mix.postCss('resources/css/tw.css', 'public/css', [
require('tailwindcss'),
])
.js('resources/js/app.js', 'public/js')
Run npm run dev. After Laravel Mix has finished building successfully, you should have a file in public/css containing built Tailwind CSS. To link to this asset in your project, add the following code:
<link href = {{ asset('css/tw.css') }} rel = "stylesheet" />
Now you should be all set to go. Happy coding!