vite-plugin-pages-sitemap

raw JSON →
1.7.1 verified Mon Apr 27 auth: no javascript

Sitemap generator plugin for Vite that integrates with vite-plugin-pages to automatically generate sitemaps from file-based routing. Version 1.7.1 is the current stable release. The plugin is actively maintained. Key differentiators: it leverages the routes generated by vite-plugin-pages, supports dynamic routes, i18n with alternate links, custom hostname, exclusion patterns, and configuration for changefreq, priority, lastmod, and readable XML output. It also integrates with Nuxt.js style route naming and can generate a robots.txt. Alternative to generic sitemap generators when using vite-plugin-pages.

error Cannot find module 'vite-plugin-pages-sitemap'
cause Package not installed or module resolution issue.
fix
Run npm install -D vite-plugin-pages-sitemap
error TypeError: generateSitemap is not a function
cause Import incorrectly as named import instead of default.
fix
Use import generateSitemap from 'vite-plugin-pages-sitemap';
error Error: Cannot read property 'route' of undefined
cause Routes not provided or undefined.
fix
Ensure you pass routes option with an array of route objects or strings.
breaking Prior to v1.0, the plugin used a different configuration API. Upgrade required.
fix Update to >=1.0.0 and adjust config to use new API: pass options to generateSitemap directly.
deprecated Passing routes as a separate option is deprecated; use the onRoutesGenerated callback instead.
fix Use onRoutesGenerated hook as shown in quickstart.
gotcha The plugin requires vite-plugin-pages as a peer dependency; must be installed separately.
fix Ensure vite-plugin-pages is installed: npm install -D vite-plugin-pages
gotcha Dynamic routes must be passed as part of the routes array in generateSitemap options; not automatically detected.
fix Manually add dynamic routes to the routes array as shown in README.
gotcha The hostname option defaults to 'http://localhost/'; forgetting to set it for production will result in incorrect sitemap URLs.
fix Pass hostname option with production URL.
npm install vite-plugin-pages-sitemap
yarn add vite-plugin-pages-sitemap
pnpm add vite-plugin-pages-sitemap

Basic setup integrating vite-plugin-pages and generating a sitemap on routes generation.

import Pages from 'vite-plugin-pages';
import generateSitemap from 'vite-plugin-pages-sitemap';

export default {
  plugins: [
    Pages({
      onRoutesGenerated: (routes) => {
        generateSitemap({ routes, hostname: 'https://example.com' });
      },
    }),
  ],
};