npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-tailwind-runtime-class

v1.0.11

Published

A Vite plugin that generates runtime Tailwind CSS classes by scanning files for class definitions

Readme

Features

  • ✅ No runtime performance hit, its just an extra step at build time.
  • 🔍 Automatically scans files for runtime class definitions
  • 🔄 Hot reload support during development
  • 📦 Generates JSON output for Tailwind CSS consumption
  • ⚡ Fast file watching with hash-based change detection
  • 🎯 Configurable include/exclude patterns

⚠️ CRITICAL REQUIREMENT

The function name MUST be exactly generateRuntimeClass and CANNOT be changed, renamed, or aliased. The plugin specifically scans for this exact function name in your code. Using any other name will cause the plugin to fail silently.

// ✅ CORRECT - Plugin will detect this
const classes = generateRuntimeClass({ ... });

// ❌ WRONG - Plugin will NOT detect these
const classes = myCustomName({ ... });
const generateClasses = generateRuntimeClass;
const classes = generateClasses({ ... });
import { generateRuntimeClass as genClass } from '...';
const classes = genClass({ ... });

Installation

npm install vite-plugin-tailwind-runtime-class
# or
yarn add vite-plugin-tailwind-runtime-class
# or
pnpm add vite-plugin-tailwind-runtime-class

Usage

Vite Configuration

Add the plugin to your vite.config.ts:

import { defineConfig } from "vite";
import tailwindRuntimeClassGenerator from "vite-plugin-tailwind-runtime-class";

export default defineConfig({
 plugins: [
  tailwindRuntimeClassGenerator({
   include: ["src/**/*"],
   exclude: ["node_modules"],
   outPutPath: "./tailwind-runtime-classes.json",
  }),
 ],
});

if you are using typescript, add type definitions to your typescript.json or typescript.app.json

include: ["src", ..., "node_modules/vite-plugin-tailwind-runtime-class/dist/virtual-module.d.d.ts"]

In Your Code

Use the virtual module to generate runtime classes:

import { generateRuntimeClass } from "virtual:vite-plugin-tailwind-runtime-class";

const runtimeClasses = generateRuntimeClass({
 default: "bg-blue-500 text-white",
 sm: "bg-red-500",
 lg: "bg-green-500 text-black",
});

console.log(runtimeClasses.runtimeClass);
// Output: "bg-blue-500 text-white sm:bg-red-500 lg:bg-green-500 lg:text-black"

Options

| Option | Type | Default | Description | | ------------ | ---------- | --------------------------------------------- | --------------------------------------------- | | include | string[] | [] | File patterns to include (default: all files) | | exclude | string[] | ['node_modules'] | File patterns to exclude | | outPutPath | string | './vite-plugin-tailwind-runtime-class.json' | Output file location for Tailwind to pickup |

How It Works

  1. The plugin scans your files for calls to generateRuntimeClass()
  2. Extracts the class definitions from the function calls
  3. Generates responsive classes by prefixing with breakpoint names
  4. Writes the results to a JSON file that Tailwind can consume
  5. Watches for file changes and updates the classes in real-time

Example

Input:

const classes = generateRuntimeClass({
 default: "p-4 bg-white",
 md: "p-6",
 lg: "p-8 bg-gray-100",
});

Generated classes:

p-4 bg-white md:p-6 lg:p-8 lg:bg-gray-100

Example using class-variant-authority

Problem

Notice how we have to repeat same classes in the responsive class but with break points this time
const buttonVariants = cva("", {
 variants: {
  size: {
   sm: "h-7 px-3 py-2 text-2xs rounded-lg",
   md: "h-8 px-3 py-2 text-xs rounded-lg",
   lg: "h-[2.375rem] px-4 py-2.5 text-sm rounded-lgPlus",
   xl: "h-10 px-6 py-2 text-base rounded-lgPlus",

   // Repeat sames classes but this time with break points
   responsive: `h-7 px-3 py-2 text-2xs rounded-lg md:h-8 md:px-3 md:py-2 md:text-xs md:rounded-lg lg:h-[2.375rem] lg:px-4 lg:py-2.5 lg:text-sm lg:rounded-lgPlus xl:h-10 xl:px-6 xl:py-2 xl:text-base xl:rounded-lgPlus`,
  },
 },
});

export default function example() {
 return <button className={buttonVariants()}>example</button>;
}

Solution

No repeating, easier to maintain
import { generateRuntimeClass } from "virtual:vite-plugin-tailwind-runtime-class";

const classes = generateRuntimeClass({
 sm: "h-7 px-3 py-2 text-2xs rounded-lg",
 md: "h-8 px-3 py-2 text-xs rounded-lg",
 lg: "h-[2.375rem] px-4 py-2.5 text-sm rounded-lgPlus",
 xl: "h-10 px-6 py-2 text-base rounded-lgPlus",
});

const buttonVariants = cva("", {
 variants: {
  size: {
   ...classes,
   responsive: classes.runtimeClass, // no repeating
  },
 },
});
export default function example() {
 return <button className={buttonVariants()}>example</button>;
}

Planned updates

  • Add your own resolver so you define how the runtime classes should be calculated.

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Issues

If you find any bugs or have feature requests, please create an issue on GitHub.