yaakdoc

Next.js

Serve the docs at a path of a Next.js app with @yaakdoc/next.

@yaakdoc/next serves your yaakdoc site at a path of a Next.js app, such as /docs, in development and in production.

npm i @yaakdoc/next
next.config.ts
import type { NextConfig } from "next";
import { createNextYaakdoc } from "@yaakdoc/next";

const withYaakdoc = createNextYaakdoc({
  path: "/docs",
  export: "./yaak.json",
  config: {
    branding: {
      title: "Acme API"
    },
    pages: "per-request",
  },
});

const nextConfig: NextConfig = {};

export default withYaakdoc(nextConfig);

Add the build output to .gitignore:

.gitignore
public/docs

createNextYaakdoc(options) returns withYaakdoc. You can keep it in a file of its own and import it into next.config.ts. withYaakdoc(nextConfig) accepts an object or a function ((phase, context) => config), like any Next.js config. Next's basePath is respected.

The docs are configured inline, so you don't need a yaakdoc.config.* file. If there is one, config is merged over it. See the options.

How it works

  • next dev. The yaakdoc dev server starts in a child process, and the docs are proxied to it with rewrites. Editing the export or the theme reloads the page.
  • next build. The docs are prerendered into public/<path> and served as static files, so they're deployed with the app, on Vercel or any other host. The build replaces that folder each time, and refuses to touch one that yaakdoc didn't create.
  • next start. The docs are served from public/<path> through rewrites.
  • output: "export". The docs are part of the exported site, and no rewrites are added.

Notes

  • Trailing slashes. yaakdoc links to /docs/page/. With Next's default trailingSlash: false, these redirect to /docs/page, which then serves the page.
  • Not found pages. An unknown page under /docs shows your app's 404 page.

Options

OptionDescription
pathWhere the docs are served. Default: /docs. It takes precedence over config.base.
configyaakdoc config, merged over yaakdoc.config.* if there is one. Paths are relative to cwd.
exportPath of the Yaak export. Shorthand for config.export. By default, yaakdoc.json, then yaak.json, is looked up in cwd.
cwdProject directory. Default: process.cwd().
configFileAn explicit config file, or false to not look for one.
publicDirA folder copied to the docs' root as is. Default: none, because the app's public/ folder isn't meant for the docs.

On this page