@mvp-kit/vite-sitemap-plugin
v0.0.3
Published
Vite plugin for automatic sitemap generation from TanStack Router route tree
Maintainers
Readme
@mvp-kit/vite-sitemap-plugin
A Vite plugin for automatic sitemap generation from TanStack Router route tree.
Part of the MVPKit ecosystem - The fastest way to build production-ready web applications.
Features
- 🗺️ Automatic sitemap.xml generation from TanStack Router routes
- 🤖 robots.txt generation with sitemap reference
- ⚡ Build-time generation (zero runtime overhead)
- 🎯 SEO-optimized with customizable priorities and changefreq
- 🔧 Highly configurable with custom route handling
- 📦 TypeScript support
Installation
npm install @mvp-kit/vite-sitemap-plugin
# or
pnpm add @mvp-kit/vite-sitemap-plugin
# or
yarn add @mvp-kit/vite-sitemap-pluginUsage
Basic Setup
// vite.config.ts
import { defineConfig } from 'vite'
import { sitemapPlugin } from '@mvp-kit/vite-sitemap-plugin'
export default defineConfig({
plugins: [
// ... other plugins
sitemapPlugin({
baseUrl: 'https://your-domain.com'
})
]
})Advanced Configuration
sitemapPlugin({
baseUrl: 'https://your-domain.com',
routeTreePath: 'src/routeTree.gen.ts', // TanStack Router route tree
enabled: process.env.NODE_ENV === 'production',
includeRobots: true,
additionalRoutes: ['/sitemap'], // Add custom routes
excludeRoutes: ['/admin', '/private'], // Exclude routes
getRoutePriority: (route) => {
if (route === '/') return 1.0
if (route.startsWith('/blog')) return 0.9
return 0.8
},
getRouteChangefreq: (route) => {
if (route === '/') return 'daily'
if (route.startsWith('/blog')) return 'weekly'
return 'monthly'
}
})Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| baseUrl | string | Required | Base URL for the sitemap |
| routeTreePath | string | 'src/routeTree.gen.ts' | Path to TanStack Router route tree |
| enabled | boolean | true | Enable/disable sitemap generation |
| includeRobots | boolean | true | Generate robots.txt file |
| additionalRoutes | string[] | [] | Additional routes to include |
| excludeRoutes | string[] | [] | Routes to exclude from sitemap |
| getRoutePriority | (route: string) => number | Default logic | Custom priority function |
| getRouteChangefreq | (route: string) => string | Default logic | Custom changefreq function |
Default SEO Settings
| Route Pattern | Priority | Change Frequency |
|---------------|----------|------------------|
| / (Homepage) | 1.0 | daily |
| /blog/*, /docs/* | 0.9 | weekly |
| /api/*, /reference/* | 0.7 | monthly |
| Other routes | 0.8 | weekly |
Output
The plugin generates two files in your build output:
sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://your-domain.com/</loc>
<lastmod>2025-09-19</lastmod>
<changefreq>daily</changefreq>
<priority>1</priority>
</url>
<!-- More URLs... -->
</urlset>robots.txt
User-agent: *
Allow: /
Sitemap: https://your-domain.com/sitemap.xmlHow It Works
- Route Detection: Parses TanStack Router's
routeTree.gen.tsto extract all routes - SEO Optimization: Applies intelligent defaults or custom logic for priorities and change frequencies
- Build Integration: Runs during Vite's build process using the
closeBundlehook - File Generation: Creates sitemap.xml and robots.txt in the output directory
TypeScript Support
The plugin is written in TypeScript and includes full type definitions.
import type { SitemapPluginOptions, RouteInfo } from '@mvp-kit/vite-sitemap-plugin'More from MVPKit
- MVPKit - Complete toolkit for building production-ready web applications
- Documentation - Comprehensive guides and API reference
- Templates - Ready-to-use project templates
License
MIT
