vite-plugin-sitemap

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

Generate sitemap.xml and robots.txt automatically when building with Vite. v0.8.2 scans the dist folder after build to discover pages, supports dynamic routes, exclusion patterns, external sitemaps, i18n with alternate hreflang links, and per-route changefreq/priority/lastmod. Ships TypeScript types. Minimal configuration: just provide a hostname. Alternative to vite-plugin-pages for sitemap-only needs.

error ERROR: Cannot find module 'vite-plugin-sitemap'
cause Package not installed or missing from node_modules.
fix
Run npm install -D vite-plugin-sitemap.
error TypeError: Sitemap is not a function
cause Using named import instead of default import: `import { Sitemap } from 'vite-plugin-sitemap'`.
fix
Use default import: import Sitemap from 'vite-plugin-sitemap'.
error Error: The plugin `vite-plugin-sitemap` requires at least one route. Please provide `dynamicRoutes` or ensure your build outputs HTML files.
cause No static HTML files found in dist folder and no dynamicRoutes provided.
fix
Add dynamicRoutes array with route paths or ensure your app generates static HTML files (e.g., using SSR or prerendering).
breaking Plugin requires Vite 2.x or newer. Older Vite 1.x is not supported.
fix Upgrade Vite to version 2 or later.
gotcha Pages are discovered from the final dist folder. Only routes that produce static HTML files are included; SPA fallback pages may be missed.
fix Manually list dynamic routes using `dynamicRoutes` option.
gotcha The plugin does not support SSR or pre-rendering detection. All discovered files are added, even if they are partial HTML or API responses.
fix Use `exclude` to filter out non-page files.
deprecated The `outDir` option may conflict with Vite's `build.outDir`. Inconsistent paths can cause missing sitemap.
fix Remove `outDir` and rely on Vite's default `dist` or set `build.outDir` consistently.
npm install vite-plugin-sitemap
yarn add vite-plugin-sitemap
pnpm add vite-plugin-sitemap

Basic Vite config with Vue and sitemap plugin generating sitemap.xml at build time.

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import Sitemap from 'vite-plugin-sitemap';

export default defineConfig({
  plugins: [
    vue(),
    Sitemap({ hostname: 'https://example.com' })
  ]
});