# Tailwind CSS and NodeJS build tools in Django Docker container

**URL:** <https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788>\
**Category:** Using Django\
**Created:** [June 4, 2020, 12:59am UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788 "2020-06-04T00:59:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lancegoyke](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lancegoyke/32/944_2.png) [@lancegoyke](https://forum.djangoproject.com/u/lancegoyke)\
**Post date:** [June 4, 2020, 12:59am UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/1 "2020-06-04T00:59:54Z")

</div>

Hey all!

I’ve heard a lot of chat about fancy front end frameworks like Tailwind CSS and I’m trying to experiment to build sites that don’t look like Bootstrap, but I have a feeling I’m about to overcomplicate my life.

I wasn’t sure if one of you out there might have a more elegant solution to get `node` and `npm` up and running to help me build my Django site. I’ve been using Docker since @wsvincent released _Django for Professionals_ and really don’t want to look back.

Right now I’m at the point where I’ll just have to use the entire giant Tailwind library via CDN, but figured I’d ask if any of you had tips!

Hope everyone is staying safe!

---

<div class="post-metadata">

**Author:** ![jeff](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jeff/32/55_2.png) [@jeff](https://forum.djangoproject.com/u/jeff)\
**Post date:** [June 10, 2020, 3:14pm UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/2 "2020-06-10T15:14:58Z")

</div>

Tailwind CSS’s CDN is excellent for prototyping. I start with it, and then I switch to a locally compiled version when I am ready to ship the project. Tailwind CSS’s built-in Purge CSS support will trim a \>1M file down to about 20K or less for me, which can shave a second off of your page rendering time. So I highly recommend it.

If you are comfortable with Docker Compose, I will create a service (I call mine frontend) that is based on the Docker Node image [https://hub.docker.com/\_/node/](https://hub.docker.com/_/node/) that has a shared volume with your web service so that you can share files between each service.

I would use the node service to run `npx tailwindcss` on the fly. This is also nice for installing other JS files, which you may eventually need anyway.

---

<div class="post-metadata">

**Author:** ![galileoguzman](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/galileoguzman/32/1383_2.png) [@galileoguzman](https://forum.djangoproject.com/u/galileoguzman)\
**Post date:** [June 10, 2020, 4:01pm UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/3 "2020-06-10T16:01:52Z")

</div>

My understanding is that you want to add Tailwind CSS to your monolithic, so the best option I see is install in your Django project [django-webpack-loader](https://github.com/owais/django-webpack-loader) that is a good manager for assets, you can use with with `npm` or `yarn` (I prefer yarn).

Also we have the option of download the `scss` files of Tailwind CSS and put them inside our static folder.

Remember that Django shouldn’t serve static files in production at least you are using a static manager like [whitenoise](http://whitenoise.evans.io/en/stable/).

---

<div class="post-metadata">

**Author:** ![pydanny](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/pydanny/32/891_2.png) [@pydanny](https://forum.djangoproject.com/u/pydanny)\
**Post date:** [June 10, 2020, 4:31pm UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/4 "2020-06-10T16:31:06Z")

</div>

I’ve been using Tailwindcss for a while now, and just started a new commercial project with it. I’ve been converting a Cookiecutter Django templated project to use it and it’s been a fun process. You can watch me working on it and a few async Django views on my twitch stream at [https://twitch.tv/danielfeldroy](https://twitch.tv/danielfeldroy) starting in about 30 minutes (videos to uploaded to YouTube later today)

---

<div class="post-metadata">

**Author:** ![aquilesC](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aquilesc/32/1394_2.png) [@aquilesC](https://forum.djangoproject.com/u/aquilesC)\
**Post date:** [June 11, 2020, 10:02am UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/5 "2020-06-11T10:02:07Z")

</div>

I’ve started playing with TailwindCSS a couple of weeks ago. What really helped was quickly watching the [videos](https://www.youtube.com/watch?v=0aTRN9CSCY0&list=PL7CcGwsqRpSO3J4YU6BkWqjU0XcVSaPXl) by Adam Wathan. The pieces where he discusses the setup are very handy.

What I am currently doing, following basically to the letter what Adam suggests, is adding an extra build step, in which I run purgecss to build a small version of the css directly into the static django directory, and my base template imports this css. You can run collectstatic, etc. as with any css file.

There is one caveat, though, if you like auto-complete in your IDE, you shuld use the full css while coding, and just leave out the purgecss for deployment. I am, very slowly, building it in public on [my repository for my personal blog](https://github.com/aquilesC/aquicarattino), hope to be able to document the process soon enough.

---

<div class="post-metadata">

**Author:** ![timonweb](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/timonweb/32/570_2.png) [@timonweb](https://forum.djangoproject.com/u/timonweb)\
**Post date:** [June 12, 2020, 2:11pm UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/6 "2020-06-12T14:11:12Z")

</div>

I used it, I was even fascinated by it and created [django-tailwind](https://github.com/timonweb/django-tailwind) package. But then, after I had created several commercial projects with Tailwind, I concluded that it causes more hassle than brings benefits.

**My main gripes are:**

1. You can’t reliably build a big project without abstracting a bunch of CSS classes into reusable components. But if you do so, why do you need Tailwind in the first place?
2. I know CSS properties by heart, but I had to look for their equivalents in Tailwind. What’s the point?
3. The resulting file is huge, of course, you can use CSS nano or equivalents to trim it down, but why should you do that? What do you get in exchange?
4. The CSS compilation time is slow compared to SASS compilation times.

**IMO if you:**

1. want a quick tool for prototyping and want to get immediate results while tweaking CSS - then browser-sync is your friend. Use it with SASS, LESS, or plain CSS, and be happy.
2. don’t want your sites to look like bootstrap - feel free to start from scratch. Today we have [Grid](https://css-tricks.com/snippets/css/complete-guide-grid/), [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) and [CSS Variables](https://www.freecodecamp.org/news/everything-you-need-to-know-about-css-variables-c74d922ea855/) it’s never been easier to roll out your own CSS framework.
3. want a way to organize your CSS properties like colors, spacing, font-sizes, etc., and to be able to use them consistently throughout a project, then CSS Variables (again) is your friend. Additionally, you could look at [SASS Variables.](https://sass-lang.com/documentation/variables).

I’m not pooping at Tailwind here, no I’m just sharing my perspective and experience. These are a few thoughts from a person who was so adored by Tailwind that even created a Django package for it.

---

<div class="post-metadata">

**Author:** ![lancegoyke](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lancegoyke/32/944_2.png) [@lancegoyke](https://forum.djangoproject.com/u/lancegoyke)\
**Post date:** [June 13, 2020, 4:12pm UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/7 "2020-06-13T16:12:36Z")

</div>

> [@jeff](#):
>
> If you are comfortable with Docker Compose, I will create a service (I call mine frontend) that is based on the Docker Node image [Docker](https://hub.docker.com/_/node/) that has a shared volume with your web service so that you can share files between each service.

Thanks for the advice, @jeff. I had a feeling that a new Node service would be what I’d need, but volumes will require more research.

> [@galileoguzman](#):
>
> install in your Django project `django-webpack-loader`

Thanks for the tip, @galileoguzman. I’m totally unfamiliar with webpack at this point, but it keeps popping up in my reading.

> [@pydanny](#):
>
> I’ve been converting a Cookiecutter Django templated project to use it and it’s been a fun process.

Awesome, @pydanny, I’ll have to peek in on that more regularly. I actually saw one posted somewhere the other day, but didn’t have time to stay for long. Would you want to post a link here to your YouTube channel hosting the videos?

> [@aquilesC](#):
>
> What really helped was quickly watching the [videos](https://www.youtube.com/watch?v=0aTRN9CSCY0&list=PL7CcGwsqRpSO3J4YU6BkWqjU0XcVSaPXl) by Adam Wathan. The pieces where he discusses the setup are very handy.

@aquilesC - absolutely! Those videos are great.

> [@aquilesC](#):
>
> What I am currently doing, following basically to the letter what Adam suggests, is adding an extra build step, in which I run purgecss to build a small version of the css directly into the static django directory, and my base template imports this css. You can run collectstatic, etc. as with any css file.

Funny, this is exactly the solution I came to on my own. It wasn’t obvious to me right off the bat that I don’t really need Node in production.

> [@aquilesC](#):
>
> There is one caveat, though, if you like auto-complete in your IDE, you shuld use the full css while coding, and just leave out the purgecss for deployment.

Noob question, but to clarify: do you mean the IDE won’t find the Tailwind classes if they aren’t listed in a file?

> [@timonweb](#):
>
> I concluded that it causes more hassle than brings benefits.

@timonweb - I appreciate the critical review. Until now, I don’t think I’ve heard anyone really speak to the drawbacks. And thanks for the learning links. I’ll admit I’m unfamiliar with Grid and CSS Variables at this point.

---

<div class="post-metadata">

**Author:** ![aquilesC](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aquilesc/32/1394_2.png) [@aquilesC](https://forum.djangoproject.com/u/aquilesC)\
**Post date:** [June 14, 2020, 7:39am UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/8 "2020-06-14T07:39:25Z")

</div>

> [@lancegoyke](#):
>
> Noob question, but to clarify: do you mean the IDE won’t find the Tailwind classes if they aren’t listed in a file?

I am a big fan of PyCharm, and (I have to admit I didn’t try this hard enough) didn’t find a plugin to work with Tailwind. Therefore, I needed the full css in order for PyCharm to pick up the available classes. I believe the guys at Tailwind have released a plugin for VSCode.

> [@lancegoyke](#):
>
> Funny, this is exactly the solution I came to on my own. It wasn’t obvious to me right off the bat that I don’t really need Node in production.

Indeed. It took me a while to find a setup I am comfortable with. I think there are no magical recipes, you have to find out the best for you (or your team).

---

<div class="post-metadata">

**Author:** ![jarod51](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/jarod51/32/1440_2.png) [@jarod51](https://forum.djangoproject.com/u/jarod51)\
**Post date:** [June 15, 2020, 1:38pm UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/9 "2020-06-15T13:38:42Z")

</div>

Hi @aquilesC 🙂 Could you please share your asset pipeline for Tailwind ?

[Here is a gist of mine](https://gist.github.com/jarod51/a7fedafc67fc7c01bae8fd6c47148fec), inspired by @pydanny cookie cutter but i am not very confident with it… i am starting Django dev 🙂

---

<div class="post-metadata">

**Author:** ![mblayman](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mblayman/32/101_2.png) [@mblayman](https://forum.djangoproject.com/u/mblayman)\
**Post date:** [December 6, 2020, 6:01pm UTC](https://forum.djangoproject.com/t/tailwind-css-and-nodejs-build-tools-in-django-docker-container/2788/10 "2020-12-06T18:01:30Z")

</div>

I wrote up an opinionated take on how to set up Tailwind in Django. I also included extra stuff for Heroku configuration since that’s where I run my app. It might help others who are thinking of adding Tailwind.

> **[How To Set Up Tailwind CSS In Django On Heroku · Matt Layman](https://www.mattlayman.com/blog/2020/tailwind-django-heroku/)**
>
> In this quick article, I showed how I set up Tailwind CSS for my Django app on Heroku.
