64b284c834820f858b9720d37fee5e73eea8a0ab
@unom/vite-sitemap-plugin
Vite plugin that writes sitemap.xml and robots.txt into your output directory at build start. Supports optional i18n routing with hreflang alternates.
Install
bun add -D @unom/vite-sitemap-plugin
# or: npm i -D @unom/vite-sitemap-plugin
Usage
// vite.config.ts
import { defineConfig } from "vite";
import { sitemapPlugin } from "@unom/vite-sitemap-plugin";
export default defineConfig({
plugins: [
sitemapPlugin({
siteUrl: "https://example.com",
routes: ["", "/about", { path: "/blog", changefreq: "weekly", priority: 0.8 }],
robots: {
disallow: ["/admin/"],
},
}),
],
});
With locales (hreflang)
sitemapPlugin({
siteUrl: "https://example.com",
locales: ["en", "de", "es"],
defaultLocale: "en",
routes: ["", "/legal/imprint", "/legal/privacy"],
});
This emits one <url> per (locale, path) pair with <xhtml:link rel="alternate" hreflang="…"> entries and an x-default pointing to defaultLocale.
Options
| Option | Type | Default |
|---|---|---|
siteUrl |
string (required) |
— |
routes |
Array<string | SitemapEntry> (required) |
— |
locales |
string[] |
unset |
defaultLocale |
string |
first locale |
formatUrl |
(locale, path) => string |
${siteUrl}/${locale}${path} |
lastmod |
string | Date |
build time |
outDir |
string |
"public" |
sitemapFilename |
string |
"sitemap.xml" |
robotsFilename |
string |
"robots.txt" |
robots |
RobotsOptions | false |
{} |
name |
string |
"vite-sitemap-plugin" |
SitemapEntry accepts path, lastmod, changefreq, priority.
RobotsOptions accepts disallow, allow, extraLines, userAgent.
License
MIT
Description
Languages
TypeScript
100%