aicrawlable

How to add llms.txt to Docusaurus

A documentation site is the textbook use case for llms.txt — your sidebar is already a curated index of exactly the pages an AI should read. Docusaurus makes serving the file trivial: it's a static-site generator, so you fully control the output root.

Generate the file first — paste your docs URL and get a spec-compliant llms.txt built from your real pages, then drop it in with the method below.

Generate my llms.txt →

Method A — Static file (simplest)

Drop the file at static/llms.txt. Everything in static/ is copied verbatim to the build output root, so after npm run build it's live at /llms.txt with the correct text/plain type. Add static/llms-full.txt the same way for the full-text bundle.

Method B — Generate at build time from your docs

Want the file to stay in sync as docs change? Write it in a small lifecycle plugin that runs during postBuild, straight into the build output:

// plugins/llms-txt/index.js
const fs = require("fs");
const path = require("path");

module.exports = function llmsTxtPlugin() {
  return {
    name: "llms-txt-plugin",
    async postBuild({ outDir, siteConfig }) {
      const base = siteConfig.url;
      const body = `# ${siteConfig.title}

> ${siteConfig.tagline}

## Docs
- [Introduction](${base}/docs/intro): start here
- [Guides](${base}/docs/guides): step-by-step tutorials
- [API](${base}/docs/api): reference
`;
      fs.writeFileSync(path.join(outDir, "llms.txt"), body);
    },
  };
};

// docusaurus.config.js
module.exports = {
  plugins: [require.resolve("./plugins/llms-txt")],
};

Build the link list from your sidebars.js or by globbing docs/**/*.md frontmatter so the index tracks your real docs.

What to watch for

Generate llms.txt and llms-full.txt from your docs URL, then ship it with Method A or B.

Try the free llms.txt generator →

Related: llms.txt for VitePress · llms.txt for Next.js · How to create llms.txt · vs sitemap.xml