Shadcn.io is not affiliated with official shadcn/ui
Gatsby
Install shadcn/ui in Gatsby with the official CLI. Tailwind v3, webpack aliases, then add a component from the shadcn.io registry.
Official still documents Gatsby on Tailwind v3. For a new site, prefer Next.js, Vite, or Astro — those ship Tailwind v4. Existing Gatsby: npm init gatsby, TypeScript + Tailwind, then the alias files, then init.
Tailwind v3 only
This guide is Gatsby + Tailwind v3. New work should use a framework that supports v4.
Create the project
npm init gatsbyPrompts:
✔ What would you like to call your site?
· your-app-name
✔ What would you like to name the folder where your site will be created?
· your-app-name
✔ Will you be using JavaScript or TypeScript?
· TypeScript
✔ Will you be using a CMS?
· Choose whatever you want
✔ Would you like to install a styling system?
· Tailwind CSS
✔ Would you like to install additional features with other plugins?
· Choose whatever you want
✔ Shall we do this? (Y/n) · Yestsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}gatsby-node.ts
Create it at the repo root if it is missing.
import * as path from "path"
export const onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
"@/components": path.resolve(__dirname, "src/components"),
"@/lib/utils": path.resolve(__dirname, "src/lib/utils"),
},
},
})
}Run init
npx shadcn@latest initAdd a component
npx shadcn@latest add https://www.shadcn.io/r/button.jsonimport { Button } from "@/components/ui/button"
export default function Home() {
return (
<div>
<Button>Click me</Button>
</div>
)
}Questions
Related
Was this page helpful?
Sign in to leave feedback.
TanStack Router
Install shadcn/ui in a TanStack Router SPA. create-tsrouter-app with Tailwind and the shadcn add-on, then add a component from the shadcn.io registry.
Manual
Install shadcn/ui by hand. Tailwind, aliases, cn(), components.json, then add a component from the shadcn.io registry with the official CLI.