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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
B
Blog RSS Feed
Recent Announcements
Recent Announcements
Vercel News
Vercel News
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
H
Help Net Security
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
G
Google Developers Blog
罗磊的独立博客
爱范儿
爱范儿
宝玉的分享
宝玉的分享
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
月光博客
月光博客
人人都是产品经理
人人都是产品经理
Apple Machine Learning Research
Apple Machine Learning Research

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
Sharing Tailwind CSS Styles Across Apps in a Monorepo | N...
Juri Strumpflohner · 2026-04-10 · via Nx Blog

When you have multiple apps in a monorepo, you want consistent design tokens: colors, typography, spacing, shadows. Copy-pasting a Tailwind config between apps doesn't scale. Every time you tweak a color, you have to update it everywhere.

Tailwind v4 makes this simpler. The new CSS-first configuration with @theme means your design tokens live in a plain CSS file. In a pnpm/npm workspaces based monorepo you can put that CSS file in its own package and share it just as you'd do with your TypeScript packages.

This article walks through the mechanics of how to set that up. We'll create a shared styles package, consume it from multiple apps, and automate the Tailwind content scanning so it all stays in sync.

The Workspace Structure

For the purpose of this demo I just created two apps and a shared styles project.

apps/
  shop/          # React + Vite app
  admin/         # React + Vite app
packages/
  shared/
    styles/      # Shared design tokens

Both apps use the same colors and typography, but they're completely independent otherwise.

Create a new folder in packages/shared/styles. Create a package.json with the following content:

packages/shared/styles/package.json

{
  "name": "@org/shared-styles",
  "version": "0.0.1",
  "type": "module",
  "main": "./src/globals.css",
  "exports": {
    ".": "./src/globals.css",
    "./globals.css": "./src/globals.css"
  }
}

There's no build step involved. All we want to do is tell your package manager (pnpm/npm) where to find our @org/shared-styles package so we can import it.

The key is the exports field pointing directly to the CSS file. Any consumer can @import '@org/shared-styles' and get the tokens.

Here's an example of such CSS file using Tailwind v4's @theme directive:

packages/shared/styles/src/globals.css

@theme {
  --color-primary: oklch(55% 0.19 260);
  --color-primary-light: oklch(84% 0.07 255);
  --color-primary-dark: oklch(40% 0.17 262);

  --color-secondary: oklch(52% 0.14 175);
  --color-secondary-light: oklch(84% 0.08 175);

  --color-ink: oklch(26% 0.05 264);
  --color-ink-light: oklch(66% 0.01 258);
  --color-ink-lighter: oklch(92% 0.003 254);

  --color-canvas: oklch(97% 0.002 252);
  --color-success: oklch(55% 0.16 147);
  --color-error: oklch(59% 0.19 38);

  --font-sans: system-ui, -apple-system, sans-serif;
  --shadow-md: 0 4px 12px oklch(0% 0 0 / 10%);
  --radius-md: 0.5rem;
}

These become Tailwind utilities automatically. --color-primary gives you bg-primary, text-primary, border-primary, etc.

Each app needs three things:

1. The @tailwindcss/vite plugin in vite.config.ts:

import tailwindcss from '@tailwindcss/vite';

export default defineConfig(() => ({
  plugins: [react(), tailwindcss(), nxViteTsPaths()],
  // ...
}));

2. A dependency on the shared styles in package.json:

{
  "devDependencies": {
    "@org/shared-styles": "workspace:*"
  }
}

3. A CSS entry point that imports Tailwind and the shared tokens:

@import 'tailwindcss';
@import '@org/shared-styles';

That's it. You can now use bg-primary, text-ink, shadow-md, and all the other tokens from your shared package in any component.

The shop app uses bg-primary for its header.

Shop app using shared primary color

The admin app uses bg-secondary. Same tokens, different choices.

Admin app using shared secondary color

Automating @source Directives

Tailwind v4 needs @source directives to know which files to scan for utility classes. In a monorepo, that means pointing at every library your app depends on. Maintaining those paths by hand gets fragile fast.

Nx has sync generators that can automate this. The @juristr/nx-tailwind-sync package reads the project dependency graph and auto-manages @source directives on every build. For a deeper walkthrough on how this works, check out this blog post.

If you're not using Nx yet, you can add it to any existing pnpm or npm workspace by running nx init in the root of your project. It picks up your existing package.json scripts and workspace structure without requiring changes. From there you can wire up the sync generator.

New to Nx?

Check out our pnpm + Nx course for a step-by-step walkthrough of adding Nx to an existing workspace.

Full Example

The complete working example is on GitHub: juristr/demo-monorepo-share-tailwind-styles.

Clone it, run pnpm install, then pnpm nx dev shop or pnpm nx dev admin to see both apps using the shared design tokens.

Learn More