Join our Discord Community
Installation

Install shadcn/ui Gatsby

How to install shadcn/ui in Gatsby projects. Setup guide for static site generation with React components.

How to install shadcn/ui with Gatsby

Gatsby's static site generation combined with shadcn/ui components gives you blazing fast marketing sites, blogs, and documentation with interactive elements where needed.

Gatsby setup guide

Create a new Gatsby site

npm init gatsby
cd my-gatsby-site

Follow the prompts, choosing:

  • TypeScript (recommended)
  • Tailwind CSS for styling

Configure path mapping

Add to tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

Update gatsby-node.js:

const path = require("path")

exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },
  })
}

Initialize shadcn/ui

npx shadcn@latest init

Configure when prompted:

  • Style: Choose your preference
  • Base color: Pick your theme
  • CSS variables: Yes (recommended)

Add components

npx shadcn@latest add button card navigation-menu

Use in your pages:

// src/pages/index.tsx
import * as React from "react"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"

const IndexPage = () => {
  return (
    <main className="container mx-auto p-8">
      <Card>
        <CardHeader>
          <CardTitle>Welcome to Gatsby + shadcn/ui</CardTitle>
        </CardHeader>
        <CardContent>
          <p>Build fast sites with beautiful components</p>
          <Button className="mt-4">Get Started</Button>
        </CardContent>
      </Card>
    </main>
  )
}

export default IndexPage

File structure

gatsby-config.js
components.json

Deployment

Gatsby + shadcn/ui deploys anywhere:

PlatformSetupBest For
Gatsby CloudOptimized for GatsbyOfficial Gatsby hosting
Netlify/VercelGreat DX and previewsExcellent developer experience
AWS S3 + CloudFrontCost-effective at scaleEnterprise scale and control
GitHub PagesFree for open sourceFree static site hosting

Common issues

Build errors

If you get module resolution errors during build:

// gatsby-node.js
exports.onCreateWebpackConfig = ({ stage, actions }) => {
  if (stage === "build-javascript" || stage === "develop") {
    actions.setWebpackConfig({
      resolve: {
        alias: {
          "@": path.resolve(__dirname, "src"),
        },
      },
    })
  }
}

Styling in production

Ensure Tailwind processes all component files:

// tailwind.config.js
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
  ],
}

Next steps

With Gatsby + shadcn/ui configured:

  1. Browse official components for forms, tables, and UI elements
  2. Add charts for data visualization
  3. Explore community components for extended functionality
  4. Add useful hooks to enhance your components
  5. Use pre-built blocks to quickly build common layouts

Gatsby's powerful data layer and build optimizations paired with shadcn/ui's component library creates perfect static sites that load instantly.

Questions you're probably thinking