# Gatsby

Install and configure Frakment for Gatsby.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any URL or sending an `Accept: text/markdown` header. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).

Frakment works in any Gatsby 5+ project with React 19 and Tailwind v4. This guide covers both a new project via the CLI and an existing app.

## Prerequisites [#prerequisites]

- **Gatsby** 5 or newer
- **React** 19
- **TypeScript**
- **Tailwind CSS** v4

Components target React 19 and Tailwind v4. For React 18, some components need `forwardRef` adjustments. For Tailwind v3, port the tokens from [Theming](/docs/guides/theming) manually.

## Use the CLI [#use-the-cli]

Scaffold a new Gatsby app with Frakment installed.

<Steps>
<Step>
Create project
</Step>

```bash
npm init gatsby
cd app
```

<Step>
Install Tailwind v4
</Step>

```bash
npm install tailwindcss@latest gatsby-plugin-postcss postcss
```

Add the plugin in `gatsby-config.ts`:

```ts title="gatsby-config.ts"
import type { GatsbyConfig } from "gatsby";

const config: GatsbyConfig = {
  plugins: ["gatsby-plugin-postcss"],
};

export default config;
```

Create `src/styles/global.css`:

```css title="src/styles/global.css"
@import "tailwindcss";
```

<Step>
Add components
</Step>

```bash
npx frakment@latest init
npx frakment@latest add bubble
```

<Step>
Use it
</Step>

```tsx title="src/pages/index.tsx"
import { Bubble, BubbleContent } from "@/components/ui/message";

export default function Index() {
  return (
    <Bubble>
      <BubbleContent>Hello, Frakment.</BubbleContent>
    </Bubble>
  );
}
```
</Steps>

## Existing Project [#existing-project]

Add Frakment to a Gatsby app you already created.

<Steps>
<Step>
Install Tailwind v4
</Step>

```bash
npm install tailwindcss@latest gatsby-plugin-postcss postcss
```

Register `gatsby-plugin-postcss` in `gatsby-config.ts`.

<Step>
Run frakment init
</Step>

```bash
npx frakment@latest init
```

Point to `src/styles/global.css` when prompted. The CLI injects the theme block.

<Step>
Configure the import alias
</Step>

In `tsconfig.json`:

```json title="tsconfig.json"
{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "@/*": ["./*"]
    }
  }
}
```

<Step>
Add a component
</Step>

```bash
npx frakment@latest add bubble
```
</Steps>

## Project structure [#project-structure]

<FileTree>
<FileTreeFolder name="apps" defaultOpen>
<FileTreeFile name="package.json" />

<FileTreeFile name="gatsby-config.ts" />

<FileTreeFile name="tsconfig.json" />

<FileTreeFolder name="src" defaultOpen>
<FileTreeFolder name="pages">
<FileTreeFile name="index.tsx" />
</FileTreeFolder>

<FileTreeFolder name="styles">
<FileTreeFile name="global.css" />
</FileTreeFolder>

<FileTreeFolder name="components">
<FileTreeFolder name="ui" />
</FileTreeFolder>
</FileTreeFolder>
</FileTreeFolder>
</FileTree>

## Verify [#verify]

```bash
ls src/components/ui/bubble.tsx
```

Then render it in a page. If it renders without errors, you are ready.

## Troubleshooting [#troubleshooting]

<Accordion type="single" collapsible>
<AccordionItem value="postcss">
<AccordionTrigger>
Tailwind not compiled
</AccordionTrigger>

<AccordionContent>
Gatsby does not ship Tailwind v4 out of the box. Make sure `gatsby-plugin-postcss` is registered in `gatsby-config.ts` and restart with `gatsby develop --clear-cache`.
</AccordionContent>
</AccordionItem>

<AccordionItem value="alias">
<AccordionTrigger>
Cannot resolve @/components
</AccordionTrigger>

<AccordionContent>
Gatsby puts source in `src/`. Set `"baseUrl": "src"` and `"@/*": ["./*"]` in `tsconfig.json`.
</AccordionContent>
</AccordionItem>
</Accordion>

## Next [#next]

- [Theming](/docs/guides/theming) - customize tokens and dark mode
- [Components](/docs/components) - browse the catalog
- [Gatsby docs](https://www.gatsbyjs.com/docs) - framework reference