{"id":22945,"library":"vite-ssg-sitemap","title":"vite-ssg-sitemap","description":"A sitemap generator plugin for Vite projects using vite-ssg, built on top of sitemap-ts. Version 0.10.0, actively maintained. It automates sitemap.xml and robots.txt generation during static site builds. Key differentiators: tight integration with vite-ssg's lifecycle (onFinished hook), supports dynamic routes, route-level overrides for change frequency/priority/lastmod, i18n alternate links, and customizable output options. Simpler than full-featured sitemap libraries but specifically designed for the vite-ssg ecosystem.","status":"active","version":"0.10.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install vite-ssg-sitemap","lang":"bash","label":"npm"},{"cmd":"yarn add vite-ssg-sitemap","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-ssg-sitemap","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for sitemap XML generation and validation","package":"sitemap-ts","optional":false},{"reason":"Peer dependency; integrates as a build lifecycle hook","package":"vite-ssg","optional":false}],"imports":[{"note":"Default export only. Named import will result in undefined.","wrong":"import { generateSitemap } from 'vite-ssg-sitemap'","symbol":"generateSitemap","correct":"import generateSitemap from 'vite-ssg-sitemap'"},{"note":"CJS require returns default as module.exports. Destructuring fails.","wrong":"const { generateSitemap } = require('vite-ssg-sitemap')","symbol":"generateSitemap","correct":"const generateSitemap = require('vite-ssg-sitemap')"},{"note":"Types are not runtime values; use type import for TypeScript.","wrong":"import { RouteOptionMap } from 'vite-ssg-sitemap'","symbol":"generateSitemap type","correct":"import type { RouteOptionMap, SitemapOption } from 'vite-ssg-sitemap'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport generateSitemap from 'vite-ssg-sitemap'\n\nexport default defineConfig({\n  plugins: [vue()],\n  ssgOptions: {\n    onFinished() {\n      generateSitemap({\n        hostname: 'https://example.com',\n        dynamicRoutes: ['/about', '/contact'],\n        exclude: ['/admin'],\n        readable: true,\n        i18n: {\n          defaultLanguage: 'en',\n          languages: ['fr', 'de'],\n          strategy: 'prefix'\n        }\n      })\n    }\n  }\n})","lang":"typescript","description":"Example of using generateSitemap in vite.config.ts with i18n, dynamic routes, exclusions, and readable XML."},"warnings":[{"fix":"Use `import generateSitemap from 'vite-ssg-sitemap'` (no braces).","message":"generateSitemap is a default export, not a named export. Importing with destructured { generateSitemap } yields undefined.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pass `hostname: 'https://yoursite.com'` in options.","message":"The `hostname` option defaults to 'http://localhost/', which may produce invalid sitemap URLs in production. Always set a proper hostname.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update your i18n config to { defaultLanguage?, languages: string[] }.","message":"In v0.6.0, the `i18n` option was refactored. The `defaultLanguage` property was added and `languages` is now required if using i18n. Old `lang` property removed.","severity":"breaking","affected_versions":"<0.6.0"},{"fix":"Set `outDir` to match your Vite build output directory (default 'dist').","message":"The `outDir` is relative to the project root, not the Vite build output config. If you customize Vite's build.outDir, you must set this option accordingly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Manually collect routes and pass to `dynamicRoutes`. See README for example.","message":"Version 0.6.0 removed automatic route detection from vite-ssg. You must now pass routes via `dynamicRoutes`; the plugin no longer reads the vue-router routes.","severity":"deprecated","affected_versions":">=0.6.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `import generateSitemap from 'vite-ssg-sitemap'` (default import).","cause":"Importing with named import instead of default import.","error":"TypeError: generateSitemap is not a function"},{"fix":"Pass an array of route paths to `dynamicRoutes` in options.","cause":"No `dynamicRoutes` passed and no automatic route detection (since v0.6.0).","error":"Error: No routes provided: sitemap will be empty"},{"fix":"Run `npm install -D sitemap-ts`.","cause":"Missing peer dependency sitemap-ts.","error":"Error: Cannot find module 'sitemap-ts'"},{"fix":"Ensure all route strings are URL-encoded or sanitized.","cause":"Route path contains invalid characters (e.g., spaces, reserved XML characters).","error":"Error: XML parsing failed: Invalid tag name at line X"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}