Skip to main content

How to install Tailwind CSS using Webpacker with Rails Discussion

General • Asked by Chris Oliver

Fallback

Nice addition to GoRails episode list. Would love to see more TailwindCSS with Rails videos. Also thanks for plugging your laptop power in...I was starting to panic :D

Fallback

Hahaha I noticed that too while editing. Forgot I was recording without power. :P


Fallback

Hi Chris, thanks for the interesting tutorial. I had not heard about tailwind before. Even though I like the end result I ask myself if a sass mixin library that offers the same micro classes wouldn’t also do the trick while staying close to the rails intended way of writing css. What do you think? Could one implement something like tailwind-sass and get the same benefits (plus smaller file size by default)?


Fallback
Stephen Miles MacLennan

Awesome video, tailwind looks amazing! Just a heads up, the link to the Youtube video for the building coinbase tutorial seems to be outdated (Youtube has moved it out of the 'live' category I think). Heres the link for the non-live version https://www.youtube.com/wat...

Fallback
Thanks Stephen! Good catch on the YouTube URL.

Fallback

.postcssrc file explained in this video causes a warning regarding the @apply rule. Warning disappears if tailwind is loaded before postcss-next

https://github.com/tailwind...

Fallback
Thanks for this. It helps me quite a bit!


Fallback
Awesome episode, I did everything step by step and it works fine but I'm experimenting some delay or blink on page reload with images. I think its related to how I'm using css assets with webpacker.

Some one with the same errors?

Fallback

Anyone finding application.css is not found in the webpacker manifest.json?

Module not found: Error: Can't resolve '../css/application.css'
Fallback
Yes the app don't work... screenshot :-( . You have solved? I have solved i lost to charge app/javascript/css/application.css

Fallback
I deleted a separate thread I started in the JS section as I didn't realize this one existed. 

In a nutshell, I love Tailwind and would like to use it for a forthcoming project but can't get it to deploy via Heroku. Everything appears to install correctly until compile. At that point, the logs indicate an error when loading tailwind module.

Has anyone successfully deployed to Heroku or AWS Codestar?

Fallback
As far as Heroku goes, I had to add the nodejs buildpack to my Rails app so it would properly compile Webpacker with Ruby. You basically end up with both the Ruby and Node buildpacks and that gives all the Ruby and Node/Yarn versions required to get things going.

Fallback
Thanks Chris. 

I've got the buildpacks installed and executing in order (Node, then Ruby). Deployment is normal until compile where it's throwing the following error in log:

ERROR in ./node_modules/css-loader??ref--1-2!./node_modules/postcss-loader/lib??ref--1-3!./app/javascript/src/application.css 
remote: Module build failed: Error: Loading PostCSS Plugin failed: Cannot find module 'tailwindcss'

I'm assuming I need a webpack.config.js in root (which I've added):

var tailwindcss = require('tailwindcss'); 
module.exports = { 
   plugins: [
       tailwindcss('./app/javascript/src/tailwind.js'), 
       require('autoprefixer') 
   ]
 }

I'm getting there.... :-)

Fallback

SUCCESS!

A single sentence found on the github repo for webpacker rails gem solved my issue. 

"Remember to set NODE_ENV environment variable to production during deployment or when running this rake task."

Alas, this was all I needed to run via CLI:

NODE_ENV=production ./bin/webpack

Fallback
Off topic, but Chris, how did you manage to get hot-reloading work with a simple Rails s command, without launching WP as a separate process?
Fallback
You do have to have the webpack-dev-server running separately. I usually use foreman to manage that. Without it, it won't hot reload in development, but you can have Rails automatically compile the files in-process like it does with the asset pipeline if you don't run the separate dev server.
Fallback
watch the video c l o s e l y 

Fallback
Thanks for the awesome video Chris! I took the time to encapsulate some of this behavior into a gem to easily integrate with Rails - https://github.com/IcaliaLabs/tailwindcss-rails - enjoy!
Fallback
Awesome, Abraham! Thanks for sharing!

Login or create an account to join the conversation.