vite-ssg-sitemap
Sitemap generator working with vite-ssg using sitemap-ts
Getting Started
Vue
Install:npm install -D vite-ssg
npm install -D vite-ssg-sitemap
Vite config
Add to yourvite.config.js
:import generateSitemap from 'vite-ssg-sitemap'
export default {
plugins: [
Vue(),
],
ssgOptions: {
onFinished() { generateSitemap() },
},
}
Now, run
npm build
and this will generate sitemap.xml and robots.txt files on your dist folder.hostname
- Type:
string
- Default:
'http://localhost/'
Base URI.
dynamicRoutes
- Type:
string[]
- Default:
[]
Array of strings with manual dynamic routes.
export default {
plugins: [
Vue(),
],
ssgOptions: {
onFinished() {
const users = await api.get('/users')
const dynamicRoutes = users.map(user => `/users/${user.name}`)
generateSitemap({ dynamicRoutes })
},
},
}
exclude
- Type:
string[]
- Default:
[]
Array of strings with excluded routes.
export default {
plugins: [
Vue(),
],
ssgOptions: {
onFinished() {
generateSitemap({
exclude: ['/admin', '/private']
})
},
},
}
You can find a working example in example folder.
outDir
- Type:
string
- Default:
'dist'
Output directory.
extensions
- Type:
string | string[]
- Default:
'html'
File extensions that need to be generated. Example: 'html', 'md'
changefreq
- Type:
string
- Default:
'daily'
Change frequency option for sitemap.
priority
- Type:
number
- Default:
1
Priority option for sitemap.
lastmod
- Type:
Date
- Default:
new Date()
Last modification option for sitemap.
readable
- Type:
boolean
- Default:
false
Converts XML into a human readable format
robots
- Type:
RobotOption[]
- Default:
[{ userAgent: '*', allow: '/' }]
RobotOption:
- userAgent:
string
- allow?:
string | string[]
- disallow?:
string | string[]
- crawlDelay?:
number
- cleanParam?:
string