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

transform-to-tailwindcss

v0.0.53

Published

๐ŸŽจ Revolutionary CSS-to-TailwindCSS migration tool with surgical precision. Transform legacy stylesheets to utility-first classes instantly across Vue, React, Svelte, and Astro projects.

Readme

๐ŸŽจ Transform to TailwindCSS

npm version Downloads License: MIT GitHub stars

๐Ÿš€ Effortlessly migrate legacy CSS to TailwindCSS

Automatically transform existing CSS styles into utility-first TailwindCSS classes

English | ็ฎ€ไฝ“ไธญๆ–‡


โœจ Why Choose Transform to TailwindCSS?

๐ŸŽฏ Performance First - Reduce bundle size with TailwindCSS utility classes ๐Ÿ”„ Legacy Migration - Seamlessly upgrade old projects to modern TailwindCSS โšก Developer Experience - Maintain design system consistency ๐Ÿ› ๏ธ Framework Agnostic - Support for Vue, React, Svelte, Astro and vanilla HTML ๐Ÿ“ Auto Safelist - ๐Ÿ†• Automatically collect generated class names, never lose any ๐Ÿ” Circular Protection - ๐Ÿ†• Smart protection to prevent infinite build loops ๐Ÿš€ Build Optimized - ๐Ÿ†• Smart skip, only regenerate when changes occur

Want to use UnoCSS? Try transformToUnocss!

๐Ÿš€ Quick Start

Global Installation

npm install -g transform-to-tailwindcss
# or
yarn global add transform-to-tailwindcss
# or
pnpm add -g transform-to-tailwindcss

๐ŸŽฏ CSS Preprocessor Dependencies

From v0.0.49+, install CSS preprocessors you use in your project:

# For Sass/SCSS support
npm install sass

# For Less support
npm install less less-plugin-module-resolver

# For Stylus support
npm install stylus

Why? Using peerDependencies ensures compatibility with your project's preprocessor versions and avoids conflicts.

CLI Usage

# Transform a directory
totailwindcss playground

# Revert changes
totailwindcss playground --revert

๐Ÿ†• Quick Example: Auto Safelist Generation

Transform your CSS and automatically generate a safelist for TailwindCSS in just 3 steps:

โš ๏ธ For Tailwind CSS v3.x and below users: Run npm run build once before starting development to generate the initial safelist file.

// 1. Configure your build tool
// vite.config.ts
export default defineConfig({
  plugins: [
    viteTransformToTailwindcss({
      collectClasses: true, // ๐Ÿ†• Enable auto-collection
      outputPath: './safelist-classes.js',
    }),
  ],
})
// 2. Use in your TailwindCSS config
// tailwind.config.js
const { safelistClasses } = require('./safelist-classes.js')

module.exports = {
  safelist: [...safelistClasses], // ๐ŸŽฏ Never lose classes again!
  // ... rest of your config
}
<!-- 3. Write your components normally -->
<template>
  <div class="card">
    <h1 class="title">
      Hello World
    </h1>
  </div>
</template>

<style scoped>
.card {
  padding: 20px;
  background: #f3f4f6;
}
.title {
  font-size: 24px;
  color: #1f2937;
}
</style>

<!-- โœจ Auto-generated: ["p-5", "bg-gray-100", "text-2xl", "text-gray-800"] -->

๐ŸŒˆ Usage

// vite.config.ts
import { vitePluginTransformTotailwindcss } from 'transform-to-tailwindcss'

export default defineConfig({
  plugins: [vitePluginTransformTotailwindcss(/* options */)],
})
// rollup.config.js
import { resolve } from 'node:path'
import { rollupTransformTotailwindcss } from 'transform-to-tailwindcss'

export default {
  plugins: [rollupTransformTotailwindcss(/* options */)],
}
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('transform-to-tailwindcss').webpackTransformTotailwindcss({
      /* options */
    }),
  ],
}
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('transform-to-tailwindcss').webpackTransformTotailwindcss({
        /* options */
      }),
    ],
  },
}
// esbuild.config.js
import { build } from 'esbuild'
import { esbuildTransformTotailwindcss } from 'transform-to-tailwindcss'

build({
  plugins: [esbuildTransformTotailwindcss(/* options */)],
})

๐Ÿ”ง Configuration Options

| Option | Type | Default | Description | | -------------------- | --------------- | ------------------------- | ----------------------------------------- | | ๐Ÿ› debug | boolean | false | Enable detailed transformation logs | | ๐Ÿ“ isRem | boolean | false | Convert px units to rem | | ๐ŸŽฏ include | FilterPattern | - | Files to process | | ๐Ÿšซ exclude | FilterPattern | - | Files to ignore | | ๐Ÿ“ collectClasses | boolean | false | New Auto-collect generated classes | | ๐Ÿ“‚ outputPath | string | './safelist-classes.js' | New Output path for collected classes | | โšก skipIfNoChanges | boolean | true | New Skip generation if no changes |

โš ๏ธ Important Notes for Different Tailwind CSS Versions:

  • Tailwind CSS v4.x+: Works out of the box with dynamic class generation
  • Tailwind CSS v3.x and below: Requires initial build step
    1. Configure plugin: collectClasses: true
    2. Run build: npm run build (generates safelist file)
    3. Start dev: npm run dev (uses generated safelist)
    4. Repeat step 2 when adding new CSS transformations

๐Ÿ†• Class Collection Feature

๐ŸŽฏ New Feature: Automatically collect all generated TailwindCSS class names for safelist configuration!

When using dynamic CSS transformations, TailwindCSS might not detect the generated classes during purging. The class collection feature solves this by automatically generating a safelist file containing all transformed classes.

โš ๏ธ Important for Tailwind CSS v3.x and below users: You need to run a build once first to generate the safelist file, then start your dev server for normal behavior. This is because Tailwind CSS v3.x and below require the safelist to be available during the initial compilation process.

// vite.config.js
import { viteTransformToTailwindcss } from 'transform-to-tailwindcss'

export default defineConfig({
  plugins: [
    viteTransformToTailwindcss({
      collectClasses: true, // โœ… Enable class collection
      outputPath: './config/safelist-classes.js', // ๐Ÿ“‚ Custom output path
      skipIfNoChanges: true, // โšก Performance optimization
      exclude: [
        'config/**/*', // ๐Ÿšซ Exclude config directory
        'safelist-classes.js', // ๐Ÿšซ Exclude generated file
        'tailwind.config.js', // ๐Ÿšซ Exclude Tailwind config
      ],
    }),
  ],
})
// tailwind.config.js
const { safelistClasses } = require('./config/safelist-classes.js')

module.exports = {
  content: ['./src/**/*.{html,js,vue,ts,tsx}'],
  safelist: [
    ...safelistClasses, // ๐ŸŽฏ Auto-generated classes
    // Your other safelist items...
  ],
}

Generated file (safelist-classes.js):

/**
 * Auto-generated safelist classes for Tailwind CSS
 * Generated at: 2024-01-15T10:30:00.000Z
 * Total classes: 156
 * Skip if no changes: true
 */

const safelistClasses = [
  'bg-blue-500',
  'text-white',
  'hover:bg-blue-600',
  'md:p-6',
  // ... more classes
]

module.exports = { safelistClasses }
export { safelistClasses }

Key Benefits:

  • ๐Ÿ”„ Circular Dependency Protection: Smart detection prevents infinite build loops
  • โšก Performance Optimized: Only regenerates when classes actually change
  • ๐Ÿ›ก๏ธ Build-Safe: Multiple safeguards prevent duplicate generations
  • ๐Ÿ“Š Comprehensive: Collects classes from all transformation processes

โš ๏ธ Workflow for Tailwind CSS v3.x and below:

  1. Configure the plugin with collectClasses: true
  2. Run npm run build (or your build command) once to generate safelist
  3. Start your dev server with npm run dev
  4. The generated classes will now be available during development

Other Configuration Options

debug

  • Type: boolean
  • Default: false

Enable debug mode to output detailed debugging logs during the transformation process. This is useful for troubleshooting and understanding the style transformation process.

// Example usage with debug mode enabled
viteTransformToTailwindcss({
  debug: true,
  isRem: false,
})

isRem

  • Type: boolean
  • Default: false

Convert px units to rem units during the transformation process.

include/exclude

  • Type: FilterPattern

Filter patterns for including or excluding files during the transformation process.

๐ŸŽฏ Supported Features

โœ… File Formats - .html | .tsx | .vue | .astro | .svelte โœ… CSS Preprocessors - Sass, Less, Stylus โœ… Build Tools - Vite, Rollup, Webpack, Vue CLI, ESBuild โœ… IDE Support - VS Code Extension

๐Ÿ”— Related Projects

๐Ÿ“ˆ Before & After Comparison

Before ๐Ÿ˜ค

before

After ๐ŸŽ‰

after

๐Ÿ’– Support the Project

If this project helps you, please consider giving it a โญ!

"Buy Me A Coffee"

๐Ÿ“„ License

MIT ยฉ 2024-PRESENT Simon He