Skip to content

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.

ts
// .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 ​

OptionTypePurpose
currentstringLabel of the version in sources
lateststringThe stable version, the one readers open at the root URL
versionsobjectPer-version settings: a switcher label, a source path
sourcesstringDirectory holding the current version's content
archivestringDirectory whose subfolders are archived versions
versionSwitcherobject or falseThe version dropdown, false disables it
hooks.rewritesHook(source, version, locale) => stringMaps 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:

ContentURL 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.

Moving from v2 ​

In v2 the current version was served at the root, so /guide showed the current guide. That breaks once the sources hold a release that is not out yet: the unreleased docs would own /guide, and readers coming from search engines and old links would land on them. Since v3 every version, the latest one included, is served under its name, and latest says which one is stable.

An address that names no version, such as /guide, /guide.html or /de/guide, opens the same page of the latest version, and the address bar moves to /v2.x/guide. The root, / and /<locale>/, opens the latest home page the same way. An address whose page the latest version lacks still shows the not-found page.

VitePress publishes every page at exactly one path, so serving /guide as well as /v2.x/guide would build each page of the latest version twice, and show it twice in the local search. Instead, the host serves 404.html for /guide, as it does for any address with no page, and a small script in that page opens the versioned page before the app starts. Nothing is built twice. The host still answers /guide with status 404, so search engines index only the versioned address. See Addresses Without a Version for how it works and what the host needs.

What moves for you:

LinkIn v3
Absolute links in markdown, such as /guide/Rewritten to the version of the page, nothing to do
Frontmatter links, such as hero.actionsRewritten to the version of the page, nothing to do
Nav and sidebar links, such as /guide/Rewritten to the version of the page, nothing to do
Links from outside the site, and bookmarksOpen the latest version, the address moves to /<latest>/guide/
Links in your own Vue componentsOpen the latest version with installVersionFallback
A nav activeMatch such as ^/guide/No longer matches, write ^/[^/]+/guide/

current ​

The label of the version that sources holds.

ts
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).

ts
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.

ts
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/.

text
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:

MessageCause
Version v2.x is published from both src and archive/v2.xTwo 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 folderA path is missing, or lies outside the docs root
Version v0.x in src/legacy overlaps version next in srcA 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.

ts
sources: 'src'  // or 'latest', 'content', ...
text
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.

ts
archive: 'archive'  // or 'versions', 'old', ...
text
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:

ts
const defaultConfiguration = {
    versionsConfig: {
        current: 'latest',
        latest: '',
        sources: 'src',
        archive: 'archive',
        versions: {},
        hooks: {
            rewritesHook: rewritesHook
        },
        versionSwitcher: {
            text: 'Switch Version',
            includeCurrentVersion: true
        }
    }
};

See also ​

Released under the Mozilla Public License 2.0