next-sitemap
CLI that generates sitemaps and robots.txt for Next.js sites
Repository Health
Technical Analysis
next-sitemap is a build-time CLI tool that generates sitemap.xml, sitemap indexes, and robots.txt for Next.js applications, covering static, pre-rendered, dynamic, and server-rendered pages alike. Run as a postbuild script, it scans the build output to enumerate pages automatically, then applies a next-sitemap.config.js file to control priorities, change frequencies, exclusions, and multi-sitemap splitting for large sites.
It handles the awkward cases that hand-written sitemaps miss: dynamic routes populated via getServerSideProps, i18n locale variants, and sites large enough to need sitemap indexes split across multiple files. Because it runs entirely from the CLI against build artifacts, it requires no runtime code changes to the application itself beyond a config file and a postbuild script entry.
What You Get
- A
postbuildCLI command that generates sitemap.xml automatically afternext build - Support for static, dynamic, server-rendered, and i18n-localized page routes
- Automatic sitemap index splitting for large sites via a configurable page-count threshold
- robots.txt generation with configurable disallow rules and sitemap references
- A
getServerSideSitemaphelper for fully dynamic, on-demand sitemap generation - Custom transform functions to set per-URL priority, changefreq, and lastmod values
Common Use Cases
- Generating a production sitemap.xml automatically as part of a Next.js CI/CD build pipeline
- Producing a robots.txt with environment-specific disallow rules (staging vs. production)
- Splitting a sitemap into multiple indexed files for a site with tens of thousands of pages
- Building a dynamic sitemap for a marketplace or blog where pages are generated from a database
Under The Hood
Architecture - The CLI entrypoint (packages/next-sitemap/src/cli.ts) runs a clear pipeline of single-purpose classes: ConfigParser loads next-sitemap.config.js and runtime paths, ManifestParser reads the Next.js build manifest to enumerate rendered pages, UrlSetBuilder turns that manifest into a normalized URL set applying per-page transforms, and ExportableBuilder chunks the set into sitemap files (splitting into an index when generateIndexSitemap is enabled) and writes robots.txt before exporting everything to disk. Tech Stack - A TypeScript monorepo managed with Turborepo and Bun workspaces (packages/next-sitemap, examples/*, docs), publishing dual ESM/CJS builds with generated type declarations, and depending on fast-xml-parser for sitemap XML generation. Code Quality - Each builder and parser has a colocated __tests__ directory with unit tests and Jest/Bun snapshot fixtures (e.g. generate-robots-txt.test.ts, create-url-set.test.ts, absolute-url.test.ts), and the test script runs with coverage in CI via azure-pipeline.yml, reflecting deliberate test coverage over the core sitemap/robots-txt generation logic. API Design - The tool’s primary interface is a single next-sitemap.config.js file plus a postbuild script entry, requiring no changes to application route code for static/SSR pages; the separate getServerSideSitemap helper extends the same design to fully dynamic routes without introducing a second configuration system.
Used by 7 apps in this directory
Abby
Developer Tools · Product Management
Statically typed feature flags, remote config, and A/B testing with framework-native SDKs for TypeScript teams.
Helicone
Monitoring · AI Development · Analytics
An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.
Jan
AI Assistants
Run LLMs 100% locally with full privacy, or connect to cloud AI — your machine, your data, your control.
KeystoneJS
CMS · Developer Tools
The superpowered headless CMS for developers built with GraphQL and React
LearnHouse
Learning Management · CMS
Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.
Onlook
Design Tools · AI Design Tools
An open-source, AI-first visual editor that lets designers and developers build, style, and deploy React apps directly in code — no handoff required.
Payload CMS
Developer Tools · Blogging · CMS
The open-source, Next.js-native headless CMS that lives inside your /app folder and gives you a full TypeScript backend instantly.