transform-to-unocss
| Install | |
|---|---|
npm install transform-to-unocss@0.1.23 |
|
| Latest Version: | 0.1.23 |
| License: | MIT |
| Last Updated: | Mar 26, 2026 |
| Links: | GitHub · npm |
๐ Transform to UnoCSS
Effortlessly migrate your CSS, inline styles, and preprocessors to UnoCSS
English | ็ฎไฝไธญๆ
โจ Why Transform to UnoCSS?
Transform your legacy CSS into modern, performant UnoCSS with zero configuration! This powerful tool automatically converts:
- ๐จ CSS classes โ UnoCSS utilities
- ๐๏ธ Inline styles โ Atomic classes
- ๐ญ Sass/Less/Stylus โ Pure UnoCSS
- โก Bundle size reduction up to 70%
- ๐ง Smart conflict resolution
- ๐ Debug mode for transparency
- ๐ฏ One-click rollback for safety
Perfect for modernizing legacy projects or optimizing performance. Works with Vue, React, Svelte, Astro, and more!
๐ก Pro tip: If you're using Tailwind CSS, check out our sister project transformToTailwindcss.
๐ฆ Quick Start
Global Installation
npm i -g transform-to-unocss
One-time Usage (Recommended)
npx transform-to-unocss@latest your-project-folder
โก CLI Usage
Transform your project
# Transform entire directory
tounocss playground
# Transform with debug output
tounocss playground --debug
# Revert changes (if needed)
tounocss playground --revert
# Show help
tounocss --help
๐ฏ Quick Example
Before:
<template>
<div class="container">
<h1 class="title">Hello World</h1>
<p style="color: red; font-size: 16px;">This is a paragraph</p>
</div>
</template>
<style scoped>
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: linear-gradient(to right, #ff6b6b, #4ecdc4);
}
.title {
font-size: 24px;
font-weight: bold;
color: #333;
text-align: center;
}
</style>
After:
<template>
<div class="max-w-6xl mx-auto p-5 bg-gradient-to-r from-red-400 to-teal-400">
<h1 class="text-6 font-bold text-gray-8 text-center">Hello World</h1>
<p class="text-red text-4">This is a paragraph</p>
</div>
</template>
โจ 70% smaller bundle size and zero runtime overhead!
๐ง Build Tool Integration
๐ฅ Vite (Recommended)
import { viteTransformToUnocss } from 'transform-to-unocss'
// vite.config.ts
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
viteTransformToUnocss({
include: ['**/*.vue', '**/*.tsx', '**/*.jsx'],
exclude: ['node_modules/**'],
debug: true, // Enable debug mode
}),
],
})
๐ฆ Rollup
// rollup.config.js
import { rollupTransformToUnocss } from 'transform-to-unocss'
export default {
plugins: [
rollupTransformToUnocss({
include: ['**/*.vue', '**/*.tsx', '**/*.jsx'],
debug: false,
}),
],
}
โก Webpack
// webpack.config.js
const { webpackTransformToUnocss } = require('transform-to-unocss')
module.exports = {
plugins: [
webpackTransformToUnocss({
include: ['**/*.vue', '**/*.tsx', '**/*.jsx'],
exclude: ['node_modules/**'],
}),
],
}
๐ฏ Vue CLI
// vue.config.js
const { webpackTransformToUnocss } = require('transform-to-unocss')
module.exports = {
configureWebpack: {
plugins: [
webpackTransformToUnocss({
include: ['**/*.vue'],
debug: process.env.NODE_ENV === 'development',
}),
],
},
}
โก Esbuild
// esbuild.config.js
import { build } from 'esbuild'
import { esbuildTransformToUnocss } from 'transform-to-unocss'
build({
plugins: [
esbuildTransformToUnocss({
include: ['**/*.tsx', '**/*.jsx'],
}),
],
})
๏ฟฝ Core Features
๐ฏ Smart Transformation
- โ CSS class selectors โ UnoCSS utilities
- โ Inline styles โ Atomic class attributes
- โ Preprocessors (Sass/Less/Stylus) โ Pure UnoCSS
- โ
Pseudo-classes (
:hover,:focus, etc.) - โ Media queries โ Responsive classes
- โ Complex selectors โ Smart parsing
๐ง Developer Experience
- ๐ Debug mode - Detailed transformation logs
- ๏ฟฝ One-click rollback - Safe change reversal
- ๐จ VS Code extension - To UnoCSS
- ๐ TypeScript support - Full type definitions
- ๐ Zero configuration - Works out of the box
๐๏ธ Framework Support
- โก Vue 3/2 - Full support
- โ๏ธ React - JSX/TSX support
- ๐ญ Svelte - Native support
- ๐ Astro - Component support
- ๐ HTML - Pure HTML files
๐จ Advanced Usage
Programmatic API
import { transfromCode } from 'transform-to-unocss'
// Transform Vue component
const result = await transfromCode(vueCode, {
type: 'vue',
isRem: true,
debug: true,
})
// Transform React component
const result = await transfromCode(reactCode, {
type: 'tsx',
isJsx: true,
debug: false,
})
Configuration Options
interface Options {
type?: 'vue' | 'tsx' | 'jsx' | 'html' | 'svelte' | 'astro'
isJsx?: boolean // Whether to use JSX syntax
isRem?: boolean // Whether to convert to rem units
debug?: boolean // Whether to enable debug mode
include?: string[] // File patterns to include
exclude?: string[] // File patterns to exclude
}
๐ Performance Comparison
| Project Type | Before | After | Reduction |
|---|---|---|---|
| Medium Vue Project | 245KB | 73KB | 70% โ |
| React Application | 180KB | 54KB | 68% โ |
| Enterprise Project | 890KB | 267KB | 72% โ |
๏ฟฝ๏ธ Debug Mode
Use the --debug flag for detailed transformation information:
tounocss playground --debug
Debug output includes:
- ๐ File processing progress
- ๐ฏ CSS rule transformation details
- โก Performance statistics
- ๐ Conflict resolution process
๐ Ecosystem
- transform-to-unocss-core - Browser-side CSS transformation core
- To UnoCSS - VS Code extension
- transformToTailwindcss - Tailwind CSS transformer
๐ค Contributing
We welcome all forms of contributions! Please check the Contributing Guide for details.
Development Setup
# Clone the repository
git clone https://github.com/Simon-He95/transform-to-unocss.git
# Install dependencies
pnpm install
# Development mode
pnpm dev
# Run tests
pnpm test
# Build project
pnpm build
๐ธ Visual Transformation
Before Transformation

After Transformation

Result: 70% smaller CSS bundle, better performance, and cleaner code! ๐
๐ค Contributing
We welcome all forms of contributions! Please check the Contributing Guide for details.
Development Setup
# Clone the repository
git clone https://github.com/Simon-He95/transform-to-unocss.git
# Install dependencies
pnpm install
# Development mode
pnpm dev
# Run tests
pnpm test
# Build project
pnpm build
We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
๐ Support the Project
If this project helped you, please consider:
- โญ Star this repository
- ๐ Report issues
- ๐ง Contribute code
- โ Buy me a coffee
Your support keeps this project alive and improving! ๐
๐ License
Made with โค๏ธ by Simon He
Related Packages
๐จ Revolutionary CSS-to-TailwindCSS migration tool with surgical precision. Tran...
ESLint rules that keep utility classes on the element they style, for Tailwind C...
Version History
| Version | Released | License |
|---|---|---|
| 0.1.23 | MIT | |
| 0.1.22 | MIT | |
| 0.1.21 | MIT | |
| 0.1.20 | MIT | |
| 0.1.19 | MIT | |
| 0.1.18 | MIT | |
| 0.1.17 | MIT | |
| 0.1.16 | MIT | |
| 0.1.15 | MIT | |
| 0.1.14 | MIT | |
| 0.1.13 | MIT | |
| 0.1.12 | MIT | |
| 0.1.11 | MIT | |
| 0.1.10 | MIT | |
| 0.1.9 | MIT | |
| 0.1.8 | MIT | |
| 0.1.7 | MIT | |
| 0.1.6 | MIT | |
| 0.1.5 | MIT | |
| 0.1.4 | MIT | |
| 0.1.3 | MIT | |
| 0.1.2 | MIT | |
| 0.1.1 | MIT | |
| 0.1.0 | MIT | |
| 0.0.100 | MIT | |
| 0.0.99 | MIT | |
| 0.0.98 | MIT | |
| 0.0.97 | MIT | |
| 0.0.96 | MIT | |
| 0.0.95 | MIT |
Showing the latest 30 of 123. See every release on npm
Pre-releases (2)
| Version | Released | License |
|---|---|---|
| 0.1.24-beta.4 | MIT | |
| 0.1.24-beta.3 | MIT |