Skip to content

Zero-runtime Tailwind CSS responsive utilities with better developer experience.

License

Notifications You must be signed in to change notification settings

yeasin2002/cls-extended

Repository files navigation

cls-extended

npm version npm downloads License: MIT

Zero-runtime Tailwind CSS responsive utilities with better developer experience.

Transform responsive Tailwind classes at build time with cleaner syntax and zero runtime overhead.

✨ Features

  • Zero Runtime Overhead - Build-time transformations (0KB runtime for most tools, tiny runtime for Next.js 16+)
  • 🎨 Better DX - Cleaner, more maintainable responsive syntax
  • 🔒 Type Safe - Full TypeScript support with autocomplete
  • 🔧 Universal - Works with Vite, Webpack, and more
  • 📦 Tiny - ~8KB package

🚀 Quick Start

Installation

npm install -D cls-extended
# or
pnpm add -D cls-extended
# or
yarn add -D cls-extended

Setup

Vite:

// vite.config.ts
import clsExtended from "cls-extended/adapters/vite";

export default defineConfig({
  plugins: [clsExtended()],
});

Webpack:

// webpack.config.js
import clsExtended from "cls-extended/adapters/webpack";

export default {
  plugins: [clsExtended()],
};

Usage

import { cls } from "cls-extended";

function Component() {
  return (
    <div
      className={cls("text-xl font-bold", {
        md: "text-2xl",
        lg: "text-3xl",
      })}
    >
      Responsive Text
    </div>
  );
}

Compiles to:

<div className="text-xl font-bold md:text-2xl lg:text-3xl">Responsive Text</div>

📖 How It Works

The plugin uses AST transformation to detect cls() calls during the build process and compiles them into static Tailwind class strings:

  1. Build Time: Plugin scans your code for cls() calls
  2. AST Transform: Parses and transforms using Babel
  3. Output: Generates standard Tailwind classes with zero runtime code

This means:

  • ✅ No runtime JavaScript added to your bundle
  • ✅ Transformation happens once during build
  • ✅ Production code contains only plain strings
  • ✅ Full compatibility with Tailwind's JIT mode

📚 Documentation

For detailed configuration, advanced usage, and more examples, see the package documentation.

🛠️ Development

This is a monorepo managed with pnpm and Turborepo.

Setup

# Install dependencies
pnpm install

# Build all packages
pnpm build

# Run tests
pnpm test

# Type check
pnpm typecheck

# Lint
pnpm lint

Project Structure

cls-extended/
├── packages/
│   └── cls-extended/       # Main plugin package
├── examples/
│   ├── nextjs/            # Next.js example
│   └── vite-react/        # Vite + React example

Development Workflow

# Build the plugin
pnpm --filter cls-extended build

# Run example in dev mode
pnpm --filter vite-react dev

# Run tests in watch mode
pnpm --filter cls-extended test

🤝 Contributing

Contributions are welcome! Please follow these guidelines:

Commit Convention

This project uses Conventional Commits:

  • feat: - New features (minor version bump)
  • fix: - Bug fixes (patch version bump)
  • docs: - Documentation changes
  • chore: - Maintenance tasks
  • BREAKING CHANGE: - Breaking changes (major version bump)

📄 License

MIT License © 2025-PRESENT Yeasin

🔗 Links

About

Zero-runtime Tailwind CSS responsive utilities with better developer experience.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •