수동 설치 (Manual Installation)
shadcn-svelte를 수동으로 설정하는 방법이에요. CLI를 쓰지 않고 프로젝트에 직접 Tailwind와 유틸리티를 세팅하고 싶을 때 이 절차를 따르면 돼요.
출처: 문서
본문
Tailwind 추가
sv CLI를 사용해 프로젝트에 Tailwind CSS를 추가해요.
pnpm dlx sv add tailwindcss
npx sv add tailwindcss
bun x sv add tailwindcss
의존성 추가
프로젝트에 다음 의존성을 추가해요:
pnpm i tailwind-variants cn tw-animate-css -D
npm i tailwind-variants cn tw-animate-css -D
bun install tailwind-variants cn tw-animate-css -D
아이콘 라이브러리 추가
@lucide/svelte를 설치해요:
pnpm i @lucide/svelte -D
npm i @lucide/svelte -D
bun install @lucide/svelte -D
경로 별칭 설정
SvelteKit을 사용하면서 기본 별칭 $lib를 쓰지 않는다면, svelte.config.js 파일에 해당 별칭들을 추가해야 해요.
svelte.config.js
const config = {
// ... other config
kit: {
// ... other config
alias: {
"@/*": "./path/to/lib/*",
},
},
};
SvelteKit을 사용하고 있지 않다면, tsconfig.json과 vite.config.ts에서 경로 별칭을 직접 업데이트해야 해요.
tsconfig.json
{
"compilerOptions": {
// ... other options
"paths": {
"$lib": ["./src/lib"],
"$lib/*": ["./src/lib/*"]
}
}
}
vite.config.ts
import path from "path";
export default defineConfig({
// ... other options
resolve: {
alias: {
$lib: path.resolve("./src/lib"),
},
},
});
스타일 설정
전역 CSS 파일에 다음 내용을 추가해요. CSS 변수를 활용한 테마 설정은 테마 섹션에서 더 자세히 알아볼 수 있어요.
src/routes/layout.css
@import "tailwindcss";
@import "tw-animate-css";
@custom-variant dark (&:is(.dark *));
:root {
--radius: 0.625rem;
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--card: oklch(1 0 0);
--card-foreground: oklch(0.145 0 0);
--popover: oklch(1 0 0);
--popover-foreground: oklch(0.145 0 0);
--primary: oklch(0.205 0 0);
--primary-foreground: oklch(0.985 0 0);
--secondary: oklch(0.97 0 0);
--secondary-foreground: oklch(0.205 0 0);
--muted: oklch(0.97 0 0);
--muted-foreground: oklch(0.556 0 0);
--accent: oklch(0.97 0 0);
--accent-foreground: oklch(0.205 0 0);
--destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.922 0 0);
--input: oklch(0.922 0 0);
--ring: oklch(0.708 0 0);
--chart-1: oklch(0.646 0.222 41.116);
--chart-2: oklch(0.6 0.118 184.704);
--chart-3: oklch(0.398 0.07 227.392);
--chart-4: oklch(0.828 0.189 84.429);
--chart-5: oklch(0.769 0.188 70.08);
--sidebar: oklch(0.985 0 0);
--sidebar-foreground: oklch(0.145 0 0);
--sidebar-primary: oklch(0.205 0 0);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.97 0 0);
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.708 0 0);
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--card: oklch(0.205 0 0);
--card-foreground: oklch(0.985 0 0);
--popover: oklch(0.269 0 0);
--popover-foreground: oklch(0.985 0 0);
--primary: oklch(0.922 0 0);
--primary-foreground: oklch(0.205 0 0);
--secondary: oklch(0.269 0 0);
--secondary-foreground: oklch(0.985 0 0);
--muted: oklch(0.269 0 0);
--muted-foreground: oklch(0.708 0 0);
--accent: oklch(0.371 0 0);
--accent-foreground: oklch(0.985 0 0);
--destructive: oklch(0.704 0.191 22.216);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.556 0 0);
--chart-1: oklch(0.488 0.243 264.376);
--chart-2: oklch(0.696 0.17 162.48);
--chart-3: oklch(0.769 0.188 70.08);
--chart-4: oklch(0.627 0.265 303.9);
--chart-5: oklch(0.645 0.246 16.439);
--sidebar: oklch(0.205 0 0);
--sidebar-foreground: oklch(0.985 0 0);
--sidebar-primary: oklch(0.488 0.243 264.376);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.269 0 0);
--sidebar-accent-foreground: oklch(0.985 0 0);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.439 0 0);
}
@theme inline {
--radius-sm: calc(var(--radius) * 0.6);
--radius-md: calc(var(--radius) * 0.8);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) * 1.4);
--radius-2xl: calc(var(--radius) * 1.8);
--radius-3xl: calc(var(--radius) * 2.2);
--radius-4xl: calc(var(--radius) * 2.6);
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-card: var(--card);
--color-card-foreground: var(--card-foreground);
--color-popover: var(--popover);
--color-popover-foreground: var(--popover-foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-secondary: var(--secondary);
--color-secondary-foreground: var(--secondary-foreground);
--color-muted: var(--muted);
--color-muted-foreground: var(--muted-foreground);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-destructive: var(--destructive);
--color-border: var(--border);
--color-input: var(--input);
--color-ring: var(--ring);
--color-chart-1: var(--chart-1);
--color-chart-2: var(--chart-2);
--color-chart-3: var(--chart-3);
--color-chart-4: var(--chart-4);
--color-chart-5: var(--chart-5);
--color-sidebar: var(--sidebar);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-ring: var(--sidebar-ring);
}
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
프로젝트에 맞게 필요한 만큼 자유롭게 추가하거나 수정해도 좋아요.
utils 설정
Tailwind CSS 클래스를 조건에 따라 붙이고 병합하기 쉽게 하려면 cn 헬퍼를 만들어 두는 게 좋아요.
src/lib/utils.ts
export { cn } from "cn";
앱에 스타일 가져오기
src/routes/+layout.svelte를 만들고 스타일을 가져와요:
src/routes/+layout.svelte
<script lang="ts">
import "../app.css";
let { children } = $props();
</script>
{@render children?.()}
이것으로 끝
이제 프로젝트에 컴포넌트를 추가하기 시작할 수 있어요.
pnpm dlx shadcn-svelte@latest add button
npx shadcn-svelte@latest add button
bun x shadcn-svelte@latest add button
더 알아보기 (Learn more)
원문 문서에는 Tailwind 추가부터 별칭·스타일·utils 설정까지 수동 설치의 전 과정이 담겨 있어요. CLI 자동 설치 대신 직접 세팅할 때 절차를 하나씩 따라 해 보세요.