Add Tailwind CSS to a Rails app

06-Apr-2021 1421
In this post, I walk through a minimal set of necessary steps to get Tailwind CSS v2 working with Webpacker in a Rails 6.1 app.I read several posts on the topic and each was incomplete. This is what worked for me.AssumptionsYou already have a Rails 6 app created and running locally. It is configured to run Webpacker.If those things aren't true, you'll need to get those in place for the rest of this post to make sense.Install TailwindYou'll need to install Tailwind as well as PostCSS and Autoprefixer. Webpacker is tied to PostCSS v7, so you'll need to install a compat version of Tailwind. The PostCSS and Autoprefixier versions will need to be tied back as well.Use yarn (or npm) from the base directory of your Rails project to install these dependencies:.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle