A Vite plugin to generate sitemap.xml from your application's routes.
npm install vite-plugin-sitemap-from-routes
Plugin for Vite to automatically generate a sitemap.xml file for your project during the build process.
A Vite plugin to generate sitemap.xml from your application's routes. This helps improve SEO and ensures your static site or SPA is easily discoverable by search engines.
- Automatic Sitemap Generation: Extracts route paths from your routes file and generates a valid sitemap.xml during the Vite build.
- Customizable: Configure the base URL, routes file location, and output file name.
- Supports Modern Vite: Compatible with Vite v5 and above.
``sh`
pnpm add -D vite-plugin-sitemap-from-routes
`sh`
npm install --save-dev vite-plugin-sitemap-from-routes
`sh`
bun add -d vite-plugin-sitemap-from-routes
Add the plugin to your vite.config.ts:
`ts
import { sitemapPlugin } from 'vite-plugin-sitemap-from-routes';
export default defineConfig({
plugins: [
sitemapPlugin({
baseUrl: 'https://yourdomain.com',
routesFile: 'src/routes.ts', // Path to your routes file
outputFileName: 'sitemap.xml', // Optional, defaults to sitemap.xml
}),
],
});
`
- baseUrl: The base URL for your site (required).routesFile
- : Path to your routes file, relative to the project root (required).outputFileName
- : Name of the generated sitemap file (optional).
- The plugin reads your specified routes file and extracts all static route paths.
- It ignores dynamic routes (e.g., those with : or *).sitemap.xml
- Generates a in your build output directory.
Suppose your src/routes.ts contains:
`ts`
export const routes = [
{ path: '/' },
{ path: '/about' },
{ path: '/blog' },
{ path: '/blog/:id' }, // Will be ignored
];
The generated sitemap.xml will include only /, /about, and /blog.
- pnpm build — Build the plugin for production.pnpm test
- — Run tests (ensure you have test files in src/__tests__).pnpm lint
- — Run linting and formatting checks.pnpm lint:fix
- — Auto-fix lint and formatting issues.pnpm analyze
- — Open the build stats report (after building).pnpm clean
- — Remove build and cache artifacts.
- Node.js version: see .nvmrc (currently v22.16.0)package.json`)
- Package manager: pnpm (see
- Linting: ESLint, Prettier
- Testing: Jest
- CI: GitHub Actions for build, test, coverage, and npm publish
- Requires Node.js >= 18.17.0
- Designed for Vite >= 5
Pull requests and issues are welcome! Please follow the commit message conventions (Commitizen + cz-git) and ensure all checks pass before submitting.
MIT © hebertcisco
---
For more details, see the repository.