> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://usekeltra.vercel.app/api/mcp` to find what you need.
>
> **Have feedback?** Use `submit_feedback` on the same MCP server.

# Next.js plugin \[keltra/next]

```ts [next.config.ts]
import { withKeltra } from "keltra/next";

export default withKeltra({
  basePath: "/docs",
});
```

## Signature

```ts
function withKeltra(
  nextConfig?: NextConfig | Promise<NextConfig> | NextConfigFunction,
  options?: KeltraConfig,
): NextConfigFunction;
```

* `nextConfig` is your Next.js config. It can be an object or a function, like any `next.config`.
* `options` accepts the same fields as [`keltra.config.ts`](/reference/config). They are merged over the config file, and the plugin's values win.

It returns a config function, which Next.js accepts anywhere it accepts a config. Your own settings are kept as they are.

## Behavior

| Phase | What keltra does |
| --- | --- |
| `next dev` | Generates the manifest, then watches the asset folders. Logs `[keltra] manifest updated` when it changes |
| `next build` | Generates the manifest |
| `next start` | Nothing |

If you export a function from your config, `withKeltra` calls it with the same phase and context, then adds its changes to the result.

## Base path

`withKeltra` copies `basePath` into an environment variable that `assetPath` reads, and Next.js inlines it at build time:

```text
NEXT_PUBLIC_KELTRA_BASE=/docs
```

keltra sets this itself, so don't set it by hand. It is merged into any `env` you already have. Because the value is fixed at build time, rebuild after you change `basePath`.

## Requirements

* Next.js 14 or newer. Tested on Next.js 16 with Turbopack and webpack.
* Node.js 20.19 or newer. Next.js loads `next.config.ts` through `require`, which needs a Node version that can require an ES module.
* `next` is an optional peer dependency of `keltra`, so you only need it when you use this plugin.

## Related

* [Next.js guide](/guides/nextjs)
* [Image reference](/reference/image)
