next-sitemap is a sitemap generator for Next.js applications that produces sitemap files and robots.txt for static, pre-rendered, dynamic, and server-side pages.
The tool addresses the need to maintain accurate sitemaps as Next.js applications grow and their page structures evolve. It works by running as a postbuild script that scans your Next.js project and generates XML sitemaps and robots.txt files automatically. The generator handles various page types within a single Next.js application, whether they are statically generated, dynamically rendered, or served server-side.
Developers should choose this tool if they are building Next.js applications that need search engine optimization through proper sitemap submission. It suits projects of any size, from small hobby sites to large applications with thousands of URLs. For large sites exceeding the standard sitemap URL limit, the tool can split sitemaps into multiple files and generate an index sitemap that references them. The configuration is straightforward, requiring only a basic config file in the project root, and the tool automatically loads environment variables from .env files. Custom configuration files are supported if you prefer not to use the default naming convention.
The project maintains active development with regular updates to its codebase. The tool has evolved to make index sitemaps the default behavior in recent versions, though this can be disabled for smaller sites that do not require them. Documentation is comprehensive, covering installation, configuration options, custom transformation functions for URL handling, and special considerations for different package managers like pnpm. The project includes multiple example implementations demonstrating different configuration scenarios, from basic setups to advanced use cases with custom config files and disabled index sitemaps.