惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
N
Netflix TechBlog - Medium
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Vercel News
Vercel News
P
Palo Alto Networks Blog
C
CERT Recently Published Vulnerability Notes
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
L
Lohrmann on Cybersecurity
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed
The Register - Security
The Register - Security
T
Threat Research - Cisco Blogs
P
Privacy & Cybersecurity Law Blog
A
Arctic Wolf
F
Fortinet All Blogs
V
Vulnerabilities – Threatpost
The Hacker News
The Hacker News
V
Visual Studio Blog
Know Your Adversary
Know Your Adversary
博客园 - Franky
C
Check Point Blog
P
Privacy International News Feed
NISL@THU
NISL@THU
T
Tenable Blog
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
B
Blog RSS Feed
A
About on SuperTechFans
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
G
Google Developers Blog
WordPress大学
WordPress大学
T
Threatpost
Y
Y Combinator Blog
Last Week in AI
Last Week in AI
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
T
Tor Project blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Spread Privacy
Spread Privacy

Nx Blog

Sharing Tailwind CSS Styles Across Apps in a Monorepo | Nx Blog How SiriusXM Stays Competitive by Iterating and Getting to Market Fast | Nx Blog Agentic Experience Is the New Developer Experience | Nx Blog Nx Joins the Linux Foundation and the Agentic AI Foundation | Nx Blog A Monorepo Is NOT a Monolith | Nx Blog Why we deleted (most of) our MCP tools | Nx Blog Teach Your AI Agent How to Work in a Monorepo | Nx Blog How Broadcom stays efficient and nimble with monorepos | Nx Blog Why Monorepos are King in the Age of AI | Nx Blog Nx 2026 Roadmap: Expanding Agent Autonomy, Improving Performance, Better Polyglot and More | Nx Blog End to End Autonomous AI Agent Workflows with Nx | Nx Blog Autonomous Agents at Scale | Nx Blog Scaling 700+ Projects: How Nx Became a 'No-Brainer' for Caseware | Nx Blog Configure Tailwind v4 with Angular in an Nx Monorepo | Nx Blog The Missing Multiplier for AI Agent Productivity | Nx Blog A Year of Nx Webinars | Nx Blog Wrapping Up 2025 | Nx Blog Nx 22.3 Release: Angular 21 Support, tsgo Compiler, and Prettier v3 | Nx Blog Nx Cloud Release: Agent Resource Usage | Nx Blog Nx Platform Outperforms DIY Cache by 5x | Nx Blog An Nx Carol: Past, Present, and Future of Your Monorepo | Nx Blog Nx 22.1 Release: Terminal UI on Windows, Storybook 10, Vitest 4, and more! | Nx Blog The Compounding Effect: How Nx Features Multiply Performance Gains | Nx Blog 10 Monorepo Myths Debunked: Separating Fact from Fiction | Nx Blog Nx Cloud Release: Enterprise Task Analytics | Nx Blog Watch and Rebuild Storybook Dependencies with Nx | Nx Blog Book - React for Enterprise: Timeless Architecture for Enterprise Apps | Nx Blog Beyond Remote Cache: Unlock 70% More CI Performance | Nx Blog Nx 22 Release: Expanding the build platform | Nx Blog What's the Point of Generating All This Code If You Can't Merge It? | Nx Blog What's New in Nx Self-Healing CI | Nx Blog Nx Highlights: Smarter AI integration, all-new graph UI, and big new versions of your favorite tools | Nx Blog Making the Case for Smarter Monorepos, and How to Not Get Fooled by Myths | Nx Blog Integrating Biome in 20 Minutes | Nx Blog S1ngularity - What Happened, How We Responded, What We Learned | Nx Blog Stop Babysitting Your PRs: Self-Healing CI Cuts Time to Green by 50% | Nx Blog UKG Unifies Their Codebase and Eliminates CI Overhead to Focus on Customer Value | Nx Blog How Git Worktrees Changed My AI Agent Workflow | Nx Blog Nx Cloud Workspace Graph: See Your Organization's Code Structure Like Never Before | Nx Blog Seamless Java Deployment in Nx Using Docker | Nx Blog Getting Mobile Into Your Monorepo: Android + Nx | Nx Blog Polyglot Projects Made Easy: Integrating Spring Boot into an Nx Workspace | Nx Blog The Journey of the Nx Plugin for Gradle: From Prototype to Production | Nx Blog Combining Predictability and Intelligence With Nx Generators and AI | Nx Blog A New UI For The Humble Terminal | Nx Blog Continuous tasks are a huge DX improvement | Nx Blog New and Improved Module Federation Experience with Nx | Nx Blog A New UI for Nx Migration | Nx Blog Custom Task Runners and Self-Hosted Caching Changes | Nx Blog Enterprise Angular Monorepo Patterns | Nx Blog Using Rspack with Angular | Nx Blog Angular Architecture Guide To Building Maintainable Applications at Scale | Nx Blog Modern Angular Testing with Nx | Nx Blog Nx Update: 20.5 | Nx Blog Are Monorepos the Answer to Better AI-Assisted Development? | Nx Blog Making Cursor Smarter with an MCP Server For Nx Monorepos | Nx Blog React Development for 2025 | Nx Blog Using Apollo GraphQL in an Nx Workspace | Nx Blog Angular State Management for 2025 | Nx Blog Tailoring Nx for Your Organization | Nx Blog Nx Cloud Pipelines Come To Nx Console | Nx Blog Define the relationship with monorepos | Nx Blog See your affected project graph in Nx Cloud | Nx Blog Handling CORS In Your Workspace | Nx Blog Improve your architecture and CI pipeline times with Nx projects | Nx Blog Announcing Nx 20 | Nx Blog Introducing Nx Powerpack | Nx Blog Nx 19.5 is here! Stackblitz, Bun, Incremental Builds for Vite, Gradle Test Atomizer | Nx Blog Introducing Explain with AI | Nx Blog Nx Enterprise Podcast Episode 2: Tine Kondo | Nx Blog Monorepos and CI can be a Mess - Here's How Nx and Nx Cloud Fixed It | Nx Blog Nx Enterprise Podcast Episode 1: Hicham El Hammouchi | Nx Blog Nx 19.0 Release!! | Nx Blog Manage Your Gradle Project using Nx | Nx Blog Making the Argument for Monorepos | Nx Blog Reliable CI. A new execution model fixing both flakiness and slowness | Nx Blog Monorepos - Why Speed Matters | Nx Blog Nx Agents Walkthrough: Effortlessly Fast CI Built for Monorepos | Nx Blog Launch Nx Week Recap | Nx Blog Versioning and Releasing Packages in a Monorepo | Nx Blog Fast, Effortless CI | Nx Blog Introducing @nx/nuxt Enhanced Nuxt.js Support in Nx | Nx Blog What if Nx Plugins Were More Like VSCode Extensions | Nx Blog Monorepos: the Benefits, Challenges, and Importance of Tooling Support | Nx Blog Nx — Highlights of 2023 | Nx Blog Nx 17.2 Update | Nx Blog Unit Testing Expo Apps With Jest | Nx Blog Nx Docs AI Assistant | Nx Blog State Management Nx React Native/Expo Apps with TanStack Query and Redux | Nx Blog Nx 17 has Landed | Nx Blog Nx Conf 2023 — Recap | Nx Blog Nx Raises $16M Series A | Nx Blog Introducing Playwright Support for Nx | Nx Blog Nx 16.8 Release!!! | Nx Blog Step-by-Step Guide to Creating an Expo Monorepo with Nx | Nx Blog Qwikify your Development with Nx | Nx Blog Create Your Own create-react-app CLI | Nx Blog Storybook Interaction Tests in Nx | Nx Blog Evergreen Tooling — More than Just CodeMods | Nx Blog A Practical Guide on Effective AI Use - AI as Your Peer Programmer | Nx Blog
Configure Tailwind 4 with Vite in an NPM Workspace: The Complete Guide | Nx Blog
Juri Strumpflohner · 2025-06-20 · via Nx Blog

Tailwind CSS v4 brings revolutionary changes to how we configure and use the popular utility-first framework. The simplified setup eliminates configuration files and complex PostCSS setups - you just install, import, and start building. But when working in NPM workspaces or monorepos, there's still one crucial challenge: how do you tell Tailwind which packages to scan for classes?

This guide walks you through setting up Tailwind v4 with Vite in an NPM workspace, then shows you how to automate the configuration using Nx Sync Generators to eliminate manual maintenance.

Ready-to-use Nx Community plugin available

Don't want to build your own sync generator? Use the @juristr/nx-tailwind-sync package which implements everything described in this article.

https://github.com/juristr/tailwind4-vite-npm-workspaces

Setting up Tailwind v4

Tailwind v4 introduced some nice simplifications when it comes to configuring Tailwind:

  • No more tailwind.config.js - The framework works out of the box
  • Minimal dependencies - Just tailwindcss and @tailwindcss/vite for Vite projects
  • Simple CSS import - Add @import "tailwindcss" to your stylesheet and you're ready

Since we're using Vite in this workspace, we can leverage the dedicated Tailwind Vite plugin instead of PostCSS configuration. Here's what you need:

Install the required packages at your workspace root:

{
  "devDependencies": {
    "tailwindcss": "^4.0.0",
    "@tailwindcss/vite": "^4.0.0"
  }
}

Configure your Vite setup:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
  plugins: [react(), tailwindcss()],
  // ... rest of your config
});

Add the import to your main CSS file:

The NPM workspace challenge

Consider a typical e-commerce application structured as an NPM workspace:

apps/
  shop/
    src                  <<<< where tailwind is configured
packages/
  products/
    feat-product-list/
    feat-product-detail/
    data-access-products/
  shared/
    ui/
    utils/

At this point, your application will build and serve, but you'll notice that styles from your packages/ are missing. In this modular setup, your main application (shop) depends on various feature packages, but Tailwind only scans the main app by default. This means styles defined in your packages won't be included in the final bundle, leading to missing styles and broken layouts.

Solving the scanning problem with @source directives

Tailwind v4 introduces the @source directive to address exactly this problem. You can explicitly tell Tailwind which directories to scan by adding these directives to your CSS file:

@import 'tailwindcss';

@source "../../../packages/products/feat-product-list";
@source "../../../packages/products/feat-product-detail";
@source "../../../packages/shared/ui";
...

With these directives in place, Tailwind will scan the specified packages and include any utility classes found there. Your application styles will now work correctly across all packages.

Automating @source entries - enter Nx sync generators

While @source directives solve the technical problem, they introduce a maintenance challenge:

  • manual updates required when adding or removing dependencies,
  • easy to forget updating the directives,
  • hard-to-debug issues since missing styles don't break builds (just cause visual problems), and
  • team coordination since every developer needs to remember to update these paths.

This is where automation becomes crucial and where Nx can help. Nx Sync Generators provide a powerful solution for automating configuration that needs to stay in sync with your project structure.

For our specific use case we can automate the generation of the @source directives by

  • analyzing and traversing all of the shop application's dependencies (leveraging the Nx project graph)
  • generating the @source entries into the correct styles.css file

You can follow the guide on the Nx docs for all the details on how to implement your own Nx sync generator. At a high level these are the steps you'll need:

Step 1: Add Nx Plugin development support

Step 2: Generate a new plugin into your workspace

npx nx g @nx/plugin:plugin tools/tailwind-sync-plugin

Note, you can choose whatever folder you like. I happen to use the tools/ folder for this example.

Step 3: Generate a sync generator

npx nx g @nx/plugin:generator --name=update-tailwind-globs --path=tools/tailwind-sync-plugin/src/generators/update-tailwind-globs

With that you have the infrastructure in place and we can look at the actual implementation of the sync generator:

import { Tree, createProjectGraphAsync, joinPathFragments } from '@nx/devkit';
import { SyncGeneratorResult } from 'nx/src/utils/sync-generators';

export async function updateTailwindGlobsGenerator(
  tree: Tree
): Promise<SyncGeneratorResult> {
  const appName = '@aishop/shop';
  const projectGraph = await createProjectGraphAsync();

  // Traverse all dependencies of the shop app
  const dependencies = new Set<string>();
  const queue = [appName];
  const visited = new Set<string>();

  while (queue.length > 0) {
    const current = queue.shift()!;
    if (visited.has(current)) continue;
    visited.add(current);

    const deps = projectGraph.dependencies[current] || [];
    deps.forEach((dep) => {
      dependencies.add(dep.target);
      queue.push(dep.target);
    });
  }

  // Generate @source directives for each dependency
  const sourceDirectives: string[] = [];
  dependencies.forEach((dep) => {
    const project = projectGraph.nodes[dep];
    if (project && project.data.root) {
      const relativePath = joinPathFragments('../../../', project.data.root);
      sourceDirectives.push(`@source "${relativePath}";`);
    }
  });

  // Update the styles.css file
  const stylesPath = 'apps/shop/src/styles.css';
  const currentContent = tree.read(stylesPath)?.toString() || '';

  // Insert the @source directives after @import "tailwindcss"
  // ... (implementation details)

  return {
    outOfSyncMessage: 'Tailwind @source directives updated',
  };
}

(Check out the Github repo for the full implementation)

You can manually run sync generators with nx sync, but we want this to run automatically whenever we build or serve our application. As such we can register the sync generator in the app's package.json:

{
  "name": "@aishop/shop",
  ...
  "nx": {
    "targets": {
      "build": {
        "syncGenerators": ["@aishop/tailwind-sync-plugin:update-tailwind-globs"]
      },
      "serve": {
        "syncGenerators": ["@aishop/tailwind-sync-plugin:update-tailwind-globs"]
      }
    }
  }
}

Nx sync generators in action

When you run your development server with nx serve shop, the sync generator automatically checks if your @source directives are up to date:

Tailwind Nx sync generator in action

Your CSS file is automatically updated with the correct directives based on your actual project dependencies. If you add or remove dependencies later, the next build or serve will detect the changes and update the configuration automatically.

You can find the complete implementation in this GitHub repository.

Using Tailwind v3?

If you're currently using Tailwind v3, the concept is similar but the implementation differs. Instead of updating @source directives, you'd modify the tailwind.config.js file with glob patterns.

Check out the following video which explains the same approach for Tailwind v3:

The Tailwind v3 demo repository shows how to implement this approach for older versions.

Conclusion

While Tailwind v4's simplified setup is a significant improvement, manually maintaining @source directives creates a maintenance burden in monorepos. Nx Sync Generators solve this by automatically keeping your Tailwind configuration in sync with your project dependencies, eliminating manual updates and preventing hard-to-debug styling issues.

This approach transforms configuration maintenance into a completely automated process, letting you focus on building features rather than managing paths.

Learn more