Skip to content

Commit 701447d

Browse files
committed
chore: finish shadcn-svelte demo
1 parent 36d9abc commit 701447d

11 files changed

+128
-232
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ lib-cov
99
logs
1010
node_modules
1111
temp
12+
.svelte-kit

README.md

+32-7
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
[![JSDocs][jsdocs-src]][jsdocs-href]
77
[![License][license-src]][license-href]
88

9-
Use [shadcn/ui](https://ui.shadcn.com) or [shadcn-vue](https://shadcn-vue.com) with [UnoCSS](https://unocss.dev)
9+
Use [shadcn/ui](https://ui.shadcn.com) or [shadcn-vue](https://shadcn-vue.com) or [shadcn-svelte](https://www.shadcn-svelte.com) with [UnoCSS](https://unocss.dev)
1010

1111
1. Based on [fisand/unocss-preset-shadcn](https://github.com/fisand/unocss-preset-shadcn)
1212
1. Theme can be easily customized
1313

1414
## Usage
1515

16-
Follow the [Install and configure Vite guide](https://ui.shadcn.com/docs/installation/vite) to setup shadcn/ui, or [Install and configure Vite](https://www.shadcn-vue.com/docs/installation/vite.html) to setup shadcn-vue.
16+
Follow official guide to setup shadcn/ui, shadcn-vue or shadcn-svelte.
1717

18-
Replace the second step with the following operation after setup [UnoCSS](https://unocss.dev/integrations/vite):
18+
1. [shadcn/ui](https://ui.shadcn.com/docs/installation/vite)
19+
1. [shadcn-vue](https://www.shadcn-vue.com/docs/installation/vite.html)
20+
1. [shadcn-svelte](https://www.shadcn-svelte.com/docs/installation)
21+
22+
Replace the step to setup Tailwind CSS with [UnoCSS](https://unocss.dev/integrations/vite).
23+
Then install `unocss-preset-shadcn` and `unocss-preset-animations`, and update your `unocss.config.ts`:
1924

2025
```bash
2126
ni -D unocss-preset-animations unocss-preset-shadcn
@@ -37,7 +42,7 @@ export default defineConfig({
3742
],
3843
// By default, `.ts` and `.js` files are NOT extracted.
3944
// If you want to extract them, you can use the following configuration.
40-
// It's necessary to add following configuration if you are using shadcn-vue.
45+
// It's necessary to add following configuration if you are using shadcn-vue or shadcn-svelte.
4146
content: {
4247
pipeline: {
4348
include: [
@@ -49,14 +54,16 @@ export default defineConfig({
4954
```
5055

5156
> [!IMPORTANT]
52-
> Do not run `npx shadcn-ui@latest init` or `npx shadcn-vue@latest init`
57+
> Do not run `npx shadcn-ui@latest init` or `npx shadcn-vue@latest init` or `npx shadcn-svelte@latest init` to initialize your project.
5358
5459
1. `ni lucide-react class-variance-authority clsx tailwind-merge`
55-
- Run `ni lucide-vue-next radix-vue class-variance-authority clsx tailwind-merge` if you are using shadcn-vue.
60+
- `ni lucide-vue-next radix-vue class-variance-authority clsx tailwind-merge` for shadcn-vue.
61+
- `ni lucide-svelte tailwind-variants clsx tailwind-merge` for shadcn-svelte.
5662
1. copy `utils.ts` into your project at `src/lib`
5763
1. create `components.json` in your project root and modify as needed
5864
1. `npx shadcn-ui@latest add button`
59-
- Run `npx shadcn-vue@latest add button` if you are using shadcn-vue.
65+
- `npx shadcn-vue@latest add button` for shadcn-vue.
66+
- `npx shadcn-svelte@latest add button` for shadcn-svelte.
6067

6168
> [!WARNING]
6269
> If you encounter problems adjusting animation property, this may be because [tailwind-animate](https://github.com/jamiebuilds/tailwindcss-animate) has [duplicate rules about animation and transition](https://github.com/jamiebuilds/tailwindcss-animate/pull/46). You can refer to [Migration Guide from Animations Preset for UnoCSS](https://unocss-preset-animations.aelita.me/guide/migration.html) to solve this problem.
@@ -115,6 +122,24 @@ Vue + shadcn-vue
115122
}
116123
```
117124

125+
Svelte + shadcn-svelte
126+
127+
```json
128+
{
129+
"$schema": "https://shadcn-svelte.com/schema.json",
130+
"style": "default",
131+
"tailwind": {
132+
"config": "tailwind.config.js",
133+
"css": "src/app.pcss",
134+
"baseColor": "neutral"
135+
},
136+
"aliases": {
137+
"components": "$lib/components",
138+
"utils": "$lib/utils"
139+
}
140+
}
141+
```
142+
118143
## Dynamic Theme
119144

120145
Preview the [demo](https://unocss-preset-shadcn.vercel.app).

examples/shadcn-svelte/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
"@sveltejs/adapter-auto": "^3.0.0",
1414
"@sveltejs/kit": "^2.0.0",
1515
"@sveltejs/vite-plugin-svelte": "^3.0.0",
16-
"autoprefixer": "^10.4.16",
17-
"postcss": "^8.4.32",
18-
"postcss-load-config": "^5.0.2",
16+
"@unocss/extractor-svelte": "^0.58.0",
1917
"svelte": "^4.2.7",
2018
"svelte-check": "^3.6.0",
21-
"tailwindcss": "^3.3.6",
2219
"tslib": "^2.4.1",
2320
"typescript": "^5.0.0",
21+
"unocss": "^0.58.0",
22+
"unocss-preset-animations": "^1.0.1",
23+
"unocss-preset-shadcn": "workspace:^",
2424
"vite": "^5.0.3"
2525
},
2626
"type": "module",
2727
"dependencies": {
28+
"@unocss/reset": "^0.58.0",
2829
"bits-ui": "^0.11.8",
2930
"clsx": "^2.0.0",
3031
"lucide-svelte": "^0.299.0",

examples/shadcn-svelte/postcss.config.cjs

-13
This file was deleted.

examples/shadcn-svelte/src/app.pcss

-78
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
<script>import "../app.pcss";</script><slot></slot>
1+
<script>
2+
import '@unocss/reset/tailwind.css';
3+
import 'virtual:uno.css';
4+
</script>
5+
<slot></slot>

examples/shadcn-svelte/svelte.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const config = {
1212
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
1313
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
1414
adapter: adapter(),
15+
alias: {
16+
$lib: "./src/lib",
17+
},
1518
},
1619
}
1720

examples/shadcn-svelte/tailwind.config.js

-64
This file was deleted.

examples/shadcn-svelte/uno.config.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// unocss.config.ts
2+
import { defineConfig, presetUno } from "unocss"
3+
import presetAnimations from "unocss-preset-animations"
4+
import { presetShadcn } from "unocss-preset-shadcn"
5+
6+
export default defineConfig({
7+
presets: [
8+
presetUno(),
9+
presetAnimations(),
10+
presetShadcn({
11+
color: "red",
12+
}),
13+
],
14+
// By default, `.ts` and `.js` files are NOT extracted.
15+
// If you want to extract them, you can use the following configuration.
16+
// It's necessary to add following configuration if you are using shadcn-vue.
17+
content: {
18+
pipeline: {
19+
include: [
20+
/\.(vue|svelte|[jt]s|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/,
21+
],
22+
},
23+
},
24+
})

examples/shadcn-svelte/vite.config.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { sveltekit } from "@sveltejs/kit/vite"
2+
import extractorSvelte from "@unocss/extractor-svelte"
3+
import UnoCSS from "unocss/vite"
24
import { defineConfig } from "vite"
35

46
export default defineConfig({
5-
plugins: [sveltekit()],
7+
plugins: [
8+
UnoCSS({
9+
extractors: [extractorSvelte()],
10+
/* more options */
11+
}),
12+
sveltekit(),
13+
],
614
})

0 commit comments

Comments
 (0)