Migrating from VuePress to VitePress

Get better search DX, and Vue.js team support
Print of a wood engraving depicting an innumberably large herd of bison walking directly towards the viewer. The front of the migrating herd is charging foward and has nearly reached the viewer's position.
A herd of buffalo crossing a river basin on the Upper Missouri. Wood engraving by W Thomas after W J Hays, ca 1851. Hays, William Jacob, 1830-1875. Public Domain Mark. Source: Wellcome Collection.

What

VuePress and VitePress are Vue-based static site generators which take Markdown content and export performant multipage sites. Their default themes are designed with software documentation in mind but are a good fit for any chapter-based — think Docusaurus, Starlight, etc. With custom themes, they are reasonable options for any static site — think Astro (Vue and others), Nuxt (Vue), Eleventy (can do Vue, with zero hand holding, with @11ty/is-land), Next (React).

VuePress came first, in 2018.[1] VuePress stable 1.x saw active development for about a year.[2] Late 2020 saw the first VuePress v2.[3] By then, work was well underway for VitePress[4]. At the time, VitePress was expected to be released as VuePress v3.[5] That’s not what happened: the two stayed separate. Today, VitePress is supported by the Vue.js team, and VuePress is supported by the community.[6]

Why

VuePress was my go-to software documentation framework for years. Since VitePress’s initial stable release six months prior to this writing, I’ve been migrating VuePress sites to VitePress.

The VitePress docs state

VitePress is the spiritual successor of VuePress…VitePress provides significantly better DX, better production performance, a more polished default theme, and a more flexible customization API.[7]

For me, a major benefit is site search.

VuePress supports its own search, which they warn could be slow. VuePress also supports using Algolia’s DocSearch or standard Algolia. The DocSearch team only approves sites which are “publicly available developer documentation or a technical blog”. The steps to use standard Algolia with VuePress are not well documented, and the final result is a high-friction DX; I’ve written up the process in Algolia search in VuePress without joining DocSearch.

VitePress has out-of-the-box support for minisearch. Enabling it requires just one line of code, with no additional work needed when updating site content. That’s a huge improvement over what I’d been doing with standard Algolia in VuePress. (Read more in VitePress’s local search docs.)

How

Heads up

In the following steps, I refer to paths starting with .vuepress and .vitepress. Adjust those to your setup.

It’s not uncommon to nest VuePress or VitePress in a docs directory. In that case, use docs/.vuepress instead of .vuepress and/or docs/.vitepress instead of .vitepress, or cd docs and then run the commands as I’ve written them.

These are the steps I take:

  1. Remove VuePress-specific dependencies, including anything under the @vuepress scope.

    shell
    <package manager> remove vue vuepress # and possibly `@vuepress/bundler-vite`, `@vuepress/theme-default`, "`@vuepress/plugin-blog`, etc.
  2. Add VitePress dependencies

    shell
    <package manager> add -D vitepress
  3. Initialize VitePress.

    When asked if you want to add package scripts, select yes.

    If you customized the VuePress site at all (for example, with vuepress/styles/index.scss), when asked whether you want to customize the theme select “Default Theme + Customization”.

    shell
    bun vitepress init
    # or
    npx vitepress init # N.B: not `npm`
    # or
    pnpm vitepress init
    # or
    yarn vitepress init
  4. If you initialized VitePress with “Default Theme + Customization”, install vue:

    shell
    <package manager> add -D vue
  5. Delete VitePress’s sample Markdown files

    Tip

    If you’re new to VitePress, you might want to read through these files first.

    shell
    rm api-examples.md markdown-examples.md

    and remove the references to api-examples.md and markdown-examples.md from .vitepress/config.(js|ts).

  6. Comment out the reference in .vitepress/theme/index.(js|ts) to style.css.

  7. Update .gitignore

    VuePress’s cache directory is dot-prefixed. VitePress’s is not. VitePress doesn’t have a temp directory. The change will be something like

    shell
    .vuepress/.temp
    .vuepress/.cache
    .vuepress/dist
    .vitepress/cache
    .vitepress/dist
  8. Move the public directory to the docs root

    shell
    mv .vuepress/public public
  9. Delete VuePress artifacts

    shell
    rm -rf .vuepress/.cache .vuepress/.temp .vuepress/dist
  10. Move CSS files. ⚠️ Note that VitePress will automatically discover them. Get to that later.

    shell
    mv .vuepress/styles/* .vitepress/theme
  11. Move components, etc., from .vuepress to .vitepress. For example, that might look like

    shell
    mv .vuepress/components .vitepress/components
    mv .vuepress/stores .vitepress/stores
    mv .vuepress/utilities .vitepress/utilities
  12. Migrate .vuepress/client.(js|ts) content to .vitepress/theme/index.(js|ts). For example, move everything in @vuepress/client’s defineClientConfig.enhance to the VitePress theme’s enhanceApp, like so

    .vuepress/client.ts
    ts
    import { defineClientConfig } from "@vuepress/client";
    // …
    import MyComponent from "./components/MyComponent.vue";
    // …
    
    export default defineClientConfig({
      enhance({ app }) {
        // …
        app.component("MyComponent", MyComponent);
        // …
      },
    });

    would become this

    .vitepress/theme/index.ts
    ts
    // …
    import MyComponent from "../components/MyComponent.vue";
    
    export default {
      // …
      enhanceApp({ app }) {
        // …
        app.component("MyComponent", MyComponent);
        // …
      },
      // …
    };
  13. Migrate the config. Some things are the same, some are different.

    VuePress docs: VuePress site config, VuePress theme config

    VitePress docs: VitePress site config, VitePress theme config

    The gotchas I’ve encountered:

    • VuePress’s markdown.links.externalAttrs is VitePress’s markdown.externalLinks.

    • In VuePress, to prevent external links in Markdown from opening in a new tab you do

      .vuepress/config.ts
      ts
      // …
      markdown: {
        links: {
          externalAttrs: {
            target: "",
          },
        },
      },
      // …

      In VitePress, do

      .vuepress/config.ts
      ts
      // …
      markdown: {
        externalLinks: {
          target: "_self",
        },
      },
      // …
    • VuePress’s themeConfig.navbar is VitePress’s themeConfig.nav.

    • VuePress’s themeConfig.sidebar supports URL strings and interpolating the item text from the file content, like this

      .vuepress/config.ts
      ts
      // …
      sidebar: [
        // …
        'file.md',
        // …
      ],
      // …

      VitePress’s linked sidebar items must be objects with link and an explicit text, like this:

      .vuepress/config.ts
      ts
      // …
      sidebar: [
        // …
        {
          link: 'file.md'
          text: 'The File',
        },
        // …
      ],
      // …
    • VuePress’s themeConfig.sidebar groups are under children. VuePress’s are under items.

  14. Start dev mode:

    shell
    <package manager> run docs:dev
  15. Deal with any remaining .vuepress files.

  16. Delete the .vuepress directory.

  17. If you moved any stylesheets into .vitepress,

    1. Port SCSS to CSS, and rename files to use the extension css not scss.

    2. Import them in .vitepress/theme/index.(js|ts):

      vitepress/theme/index.ts
      ts
      import "./<the file name>.css";
    3. Referring to .vitepress/theme/style.css and inspecting in the browser, figure out which of your custom VuePress styles you want to use in VitePress, and how to apply them.

  18. Delete VitePress’s sample CSS

    shell
    rm .vitepress/theme/style.css

Footnotes

  1. https://github.com/vuejs/vuepress/releases/tag/v1.0.0 ↩︎

  2. https://github.com/vuejs/vuepress/graphs/contributors ↩︎

  3. https://github.com/vuepress/core/releases/tag/v2.0.0-alpha.1 ↩︎

  4. https://github.com/vuejs/vitepress/graphs/contributors ↩︎

  5. https://github.com/vuejs/vitepress/discussions/548 ↩︎

  6. https://github.com/vuejs/vuepress#status ↩︎

  7. https://vitepress.dev/guide/what-is-vitepress#what-about-vuepress ↩︎

On the web

Links

Also In This Series

Articles You Might Enjoy

Or Go To All Articles