Configuration Options
versionsConfig is the block defineVersionedConfig adds on top of a normal VitePress configuration. It controls where your versioned content lives, which version is the stable one, and how versions are labelled and switched.
// .vitepress/config.ts
import { defineVersionedConfig } from '@viteplus/versions';
export default defineVersionedConfig({
title: 'My Documentation',
versionsConfig: {
current: 'next',
latest: 'v2.x',
versions: {
'v1.x': { label: 'v1.x (LTS)' }
}
}
});Options
| Option | Type | Purpose |
|---|---|---|
current | string | Label of the version in sources |
latest | string | The stable version, the one readers open at the root URL |
versions | object | Per-version settings: a switcher label, a source path |
sources | string | Directory holding the current version's content |
archive | string | Directory whose subfolders are archived versions |
versionSwitcher | object or false | The version dropdown, false disables it |
hooks.rewritesHook | (source, version, locale) => string | Maps a content file to its final URL |
Every option has a default, listed under Defaults.
How versions map to URLs
Every version is a name and a folder, and every version is served under its name, the latest one included:
| Content | URL with current: 'next' and latest: 'v2.x' |
|---|---|
archive/v2.x/guide.md | /v2.x/guide |
src/guide.md | /next/guide |
archive/v1.x/guide.md | /v1.x/guide |
| (the root) | /, showing /v2.x/ in the address bar |
So a link to a page always names its version, and stays valid when a newer version becomes the latest one. The root shows the latest version's home page, see latest.
current
The label of the version that sources holds.
current: 'v2.0.x' // or 'next', 'latest', ...The pages of the sources are served under the label, so with current: 'next' the guide lives at /next/guide. It is also the stable version unless latest names another one. The label is a URL segment and a switcher entry, not a directory name, so nothing on disk has to match it.
latest
The name of the stable version: the current label, or the name of an archive folder. It is the version readers open at the root, and the switcher tags it (latest).
versionsConfig: {
current: 'next', // src holds the docs of the coming release
latest: 'v2.x' // archive/v2.x is what readers get at /
}Leave it out, or set it to '', to keep the current version as the stable one. Set it to an archive folder while sources holds documentation for a release that is not out yet, the way release branching works: the coming version is reviewed at /next/, and readers keep landing on the stable one.
The root URL
The root of the site and of every locale opens the latest version's home page, and the address changes to /v2.x/ before the page starts, without a redirect or a reload. This works on vitepress dev and on any static host, since the build copies that home page to the root index.html. A page that the site already publishes at the root is kept.
versions
Settings for individual versions, keyed by version name.
versions: {
'v1.x': { label: 'v1.x (LTS)' },
'v0.x': { path: 'legacy/v0', label: 'v0.x (EOL)' }
}label
The text the version switchers show for the version. The URL keeps the version name, so changing a label never moves a page.
path
The folder that holds the version's pages, relative to the docs root. Use it for a version that lives outside archive, for example a worktree of a release branch checked out inside docs/.
docs/
├── src/ → /next/
├── archive/
│ └── v1.x/ → /v1.x/
└── legacy/
└── v0/ → /v0.x/ (versions: { 'v0.x': { path: 'legacy/v0' } })VitePress builds only the files inside the docs root, so the folder has to exist inside it. It also has to be a folder of its own: a path inside sources or an archive folder would hand its pages to both versions. A path on the current version is rejected, since sources already places it.
Errors that stop the build
A version setup that would publish the wrong pages fails while the configuration loads, with a message that names the problem:
| Message | Cause |
|---|---|
Version v2.x is published from both src and archive/v2.x | Two versions share a name, such as an archive folder named after current |
Version v3.x is neither the current version nor ... | latest, or a key of versions, names no version |
Path ../v0 of version v0.x has to be an existing folder | A path is missing, or lies outside the docs root |
Version v0.x in src/legacy overlaps version next in src | A path lies inside the folder of another version, or holds one |
rewritesHook has to keep de/v2.x/ at the front of ... | The rewritesHook moves or drops the locale or version |
sources
The directory holding the current version's content, relative to the docs root.
sources: 'src' // or 'latest', 'content', ...docs/
└── src/ ← sources
├── index.md
└── guide/archive
The directory whose subfolders are treated as archived versions. Each subfolder name becomes that version's name: its URL prefix and its key in the per-version nav and sidebar maps.
archive: 'archive' // or 'versions', 'old', ...docs/
└── archive/ ← archive
├── v1.0.x/ → /v1.0.x/
└── v1.5.x/ → /v1.5.x/The directory is created for you, with a .gitkeep, if it does not exist.
Directory names never reach the URL
sources and archive are filesystem locations only. With sources: 'content' the current version is still served under its current label.
The version switcher builds its list from current, the archive subfolders, and the versions with a path, so adding a version needs no further configuration.
hooks
See URL Path Rewrites for customizing how content files map to URLs.
versionSwitcher
See Version Switcher for the dropdown and the VersionSwitcher component.
Defaults
Anything you omit falls back to:
const defaultConfiguration = {
versionsConfig: {
current: 'latest',
latest: '',
sources: 'src',
archive: 'archive',
versions: {},
hooks: {
rewritesHook: rewritesHook
},
versionSwitcher: {
text: 'Switch Version',
includeCurrentVersion: true
}
}
};