Home / Companies / Nx / Blog / Post Details
Content Deep Dive

Configure Tailwind v4 with Angular in an Nx Monorepo

Blog post from Nx

Post Details
Company
Nx
Date Published
Author
Juri Strumpflohner
Word Count
1,188
Language
English
Hacker News Points
-
Summary

Tailwind CSS version 4 simplifies the setup by eliminating the need for a tailwind.config.js file and requiring minimal dependencies, but poses challenges in an Nx monorepo when used with Angular, as it may lead to larger-than-necessary CSS outputs. The article delves into how Tailwind v4's scanning process interacts with Angular's PostCSS setup, causing the inclusion of unused CSS classes due to broad workspace scanning. To optimize the CSS, it suggests using @source directives and Nx Sync Generators to restrict scanning and manage dependencies. This involves configuring the PostCSS plugin to set a more specific scanning base and employing tools like @juristr/nx-tailwind-sync to automate the maintenance of @source directives. While alternative solutions like a PostCSS plugin created by Poul Hansen offer dynamic source injection during the build, the combination of source() restrictions and automated directive management with Nx Sync Generators ensures a more efficient production CSS output without manual intervention.