Running an old (or minimal) Django server that you’d rather not pollute with
node
& npm
? You can still enjoy the power of Tailwind CSS by
building the stylesheet once (locally or in CI) and deploying nothing but a
single, minified tailwind.min.css
file.
Why do it?
- No extra runtime dependencies on production. Your server stays clean, secure and easy to patch.
- Faster deploys: you upload static files only, not
node_modules
. - Predictable builds: generate CSS in CI, review the diff, ship it.
Option 1 — Build locally / in CI, commit the CSS
- Install Node once on your laptop or CI (e.g. GitHub Actions).
- From your project root:
npm install -D tailwindcss npx tailwindcss -i static/src/input.css \ -o static/css/tailwind.min.css \ --minify
- Commit
static/css/tailwind.min.css
(and optional source map).
Do not commitnode_modules
. - Deploy Django as usual, then run:
python manage.py collectstatic --no-input
Your production box serves a plain CSS file—no Node runtime required.
Option 2 — Use Tailwind’s standalone binary
Tailwind ships a self-contained Go binary that needs zero Node libraries.
curl -sSLO \
https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64
chmod +x tailwindcss-linux-x64
./tailwindcss-linux-x64 \
-i static/src/input.css \
-o static/css/tailwind.min.css \
--minify
Pick tailwindcss-linux-musl
for Alpine-based systems.
Afterwards the workflow is identical: commit or copy the generated CSS, then
collectstatic
during deployment.
Recommended Project Layout
myproject/
├── static/
│ ├── src/
│ │ └── input.css ← @tailwind directives
│ └── css/
│ └── tailwind.min.css ← compiled & committed
├── templates/
└── manage.py
Whether you trigger Tailwind manually or via a CI workflow file, you always end up with the same deliverable: one minified stylesheet ready for Django’s static pipeline.
Key Takeaways
- You don’t need Node.js on the production host.
- Build Tailwind once, deploy the compiled file.
- Standalone CLI works anywhere – even on minimal servers.
That’s it! Your legacy (or resource-constrained) Django environment can now enjoy modern Tailwind styles without any extra baggage.
Comments
Post a Comment