百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
U

unocss-preset-shadcn

> 前端框架
开源

使用 shadcn ui 与 UnoCSS 结合

394 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 shadcn ui 与 UnoCSS 结合

unocss-preset-shadcn

npm version npm downloads bundle JSDocs License

Use shadcn/ui or shadcn-vue or shadcn-svelte or SolidUI with UnoCSS.

  1. Based on fisand/unocss-preset-shadcn
  2. Theme can be easily customized

Usage

Starting from v1.0, unocss-preset-shadcn supports presetWind4 v4 by default. If you are using presetWind3, you can import the legacy preset from unocss-preset-shadcn/v3

Follow the official guide to set up shadcn/ui, shadcn-vue, or shadcn-svelte, or SolidUI. Replace the step to set up Tailwind CSS with UnoCSS.

Install the Tailwind Browser Style Reset.

Then install unocss-preset-shadcn and unocss-preset-animations, and update your unocss.config.ts:

bash
ni @unocss/reset
ni -D unocss @unocss/preset-wind3 unocss-preset-animations unocss-preset-shadcn
…

[!IMPORTANT] Do not run npx shadcn-ui@latest init or npx shadcn-vue@latest init or npx shadcn-svelte@latest init or npx solidui-cli@latest init to initialize your project.

  1. ni lucide-react class-variance-authority clsx tailwind-merge
    • ni lucide-vue-next radix-vue class-variance-authority clsx tailwind-merge for shadcn-vue.
    • ni lucide-svelte tailwind-variants clsx tailwind-merge for shadcn-svelte.
    • ni tailwindcss-animate class-variance-authority clsx tailwind-merge for SolidUI.
  2. copy utils.ts into your project at src/lib
  3. create components.json or ui.config.json (for SolidUI) in your project root and modify as needed
  4. npx shadcn-ui@latest add button
    • npx shadcn-vue@latest add button for shadcn-vue.
    • npx shadcn-svelte@latest add button for shadcn-svelte.
    • npx solidui-cli@latest add button for SolidUI.

[!WARNING] You may need an empty tailwind.config.js file in your project root to make cli commands happy.

If you encounter problems adjusting animation property, this may be because tailwind-animate has duplicate rules about animation and transition. You can refer to Migration Guide from Animations Preset for UnoCSS to solve this problem.

Code to copy

utils.ts: this file usually under src/lib folder.

typescript
import type { ClassValue } from "clsx";
import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

components.json: this file should under your project root.

React + shadcn-ui

json
{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "new-york",
  "tailwind": {
    "config": "tailwind.config.js",
    "css": "styles/global.css",
    "baseColor": "neutral",
    "cssVariables": true,
    "prefix": ""
  },
  "rsc": false,
  "tsx": true,
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui"
  }
}

Vue + shadcn-vue

json
{
  "$schema": "https://shadcn-vue.com/schema.json",
  "style": "new-york",
  "typescript": true,
  "tailwind": {
    "config": "tailwind.config.js",
    "css": "src/assets/index.css",
    "baseColor": "neutral",
    "cssVariables": true,
    "prefix": ""
  },
  "aliases": {
    "components": "@/components",
    "composables": "@/composables",
    "utils": "@/lib/utils",
    "ui": "@/components/ui",
    "lib": "@/lib"
  },
  "iconLibrary": "lucide"
}

Svelte + shadcn-svelte

json
{
  "$schema": "https://shadcn-svelte.com/schema.json",
  "style": "default",
  "tailwind": {
    "config": "tailwind.config.js",
    "css": "src/app.pcss",
    "baseColor": "neutral"
  },
  "aliases": {
    "components": "$lib/components",
    "utils": "$lib/utils"
  }
}

ui.config.json: this file should under your project root. This file is for SolidUI.

json
{
  "tsx": true,
  "componentDir": "./src/components/ui",
  "tailwind": {
    "config": "tailwind.config.js",
    "css": "src/App.css"
  },
  "aliases": {
    "path": "~/*"
  }
}

Dynamic Theme

Preview the demo.

If you want to use a dynamic theme, you can pass an array of theme objects to presetShadcn:

typescript
import { defineConfig, presetUno, UserConfig } from "unocss";
import presetAnimations from "unocss-preset-animations";
import { builtinColors, presetShadcn } from "unocss-preset-shadcn";

export default defineConfig({
  presets: [
    presetUno(),
    presetAnimations(),
    presetShadcn(builtinColors.map((c) => ({ color: c }))),
  ],
});

Add a theme sync script to your index.html. To dynamically change the theme, you can create a theme switch component.

See also

  • fisand/unocss-preset-shadcn
  • tobiasfoerg/tailwindcss-shadcn-ui

Issues· 17 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptshadcn-svelteshadcn-uishadcn-vuesolidui

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架