0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Next.js】ShadcnUIの導入・使い方

Last updated at Posted at 2026-01-31

プロジェクトでShadcnUIを使うことになったので、導入方法と基本的な使い方を残しておく。

導入手順

インストール

# -b, --base-color <base-color> : プロジェクトのベースカラーを選択できる (https://ui.shadcn.com/colors)
pnpm dlx shadcn@latest init

コンポーネントの追加

pnpm dlx shadcn@latest add button

app/page.tsx を編集して動作確認してください。

import { Button } from "@/components/ui/button";

export default function Home() {
  return (
    <div>
      <Button>Click me</Button>
    </div>
  );
}

shadcn/ui の設定ファイル components.json

  • 主な設定項目
    • $schema: スキーマ定義のURL(shadcn/ui公式のスキーマ)
    • style: コンポーネントのスタイルバリアント("new-york" または "default")
    • rsc: React Server Components を使用するかどうか
    • tsx: TypeScript を使用するかどうか
  • Tailwind CSS 設定
    • config: Tailwind設定ファイルのパス
    • css: グローバルCSSファイルのパス
    • baseColor: ベースカラー("neutral")
    • cssVariables: CSS変数を使用するかどうか
    • prefix: クラス名のプレフィックス
  • その他
    • iconLibrary: 使用するアイコンライブラリ("lucide")
    • aliases: パスエイリアスの定義(@/components, @/libなど)
    • registries: カスタムコンポーネントレジストリの設定
components.json
{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "new-york",
  "rsc": true,
  "tsx": true,
  "tailwind": {
    "config": "",
    "css": "app/globals.css",
    "baseColor": "neutral",
    "cssVariables": true,
    "prefix": ""
  },
  "iconLibrary": "lucide",
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui",
    "lib": "@/lib",
    "hooks": "@/hooks"
  },
  "registries": {}
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?