Lab 06: CSS-in-JS Architecture

Time: 60 minutes | Level: Architect | Docker: node:20-alpine

Overview

Zero-runtime CSS-in-JS at scale: Vanilla Extract (style/styleVariants/recipe/globalStyle), design token integration, TypeScript-first type-safe styles, CSS Modules composition, and Tailwind JIT configuration with custom plugins.


Step 1: Zero-Runtime CSS-in-JS Architecture

Runtime cost comparison:
  styled-components:   ~13KB runtime + style injection cost
  Emotion:             ~11KB runtime + style injection cost
  Vanilla Extract:     0B runtime (compiled to static CSS)
  CSS Modules:         0B runtime (webpack/vite transform)
  Tailwind JIT:        0B runtime (static utility classes)

Zero-runtime wins for:
  - SSR/SSG (no hydration mismatch)
  - Core Web Vitals (no FOUC)
  - Bundle size
  - CSP compliance (no style injection)

Step 2: Vanilla Extract — Core API


Step 3: styleVariants and Recipe Pattern

💡 Vanilla Extract ships a TypeScript plugin that provides autocomplete for variant keys — no runtime type errors possible.


Step 4: Design Token Integration


Step 5: CSS Modules Composition


Step 6: Tailwind JIT Config + Custom Plugin


Step 7: Bundle Analysis


Step 8: Capstone — Vanilla Extract Setup Verification

📸 Verified Output:


Summary

Approach
Runtime Cost
Type Safety
DX
Use When

Vanilla Extract

0B

TypeScript native

Excellent

New projects

CSS Modules

0B

Limited

Good

Legacy/simple

Tailwind JIT

0B

Via types plugin

Good

Utility-first

styled-components

~13KB

Good

Excellent

React/theming

Emotion

~11KB

Good

Excellent

React/dynamic

Last updated