Vite SSG

28.3.0 · active · verified Sun Apr 19

Vite SSG is a library designed for static-site generation (SSG) of Vue 3 applications built with Vite. It streamlines the process of pre-rendering your Vue application into static HTML files, enhancing SEO and initial load performance. The current stable version is v28.3.0, and the project maintains a regular release cadence, often aligning with updates to its peer dependencies like Vite and Vue Router, with occasional minor and patch releases. Key differentiators include its tight integration with the Vite ecosystem, built-in support for `@unhead/vue` for document head management, and automatic critical CSS generation via the `beasties` package. Since v27.0.0, Vite SSG has exclusively adopted an ESM-only module format, dropping CommonJS support entirely. It supports Vue Router for multi-page SSG and offers a specialized entry point for single-page SSG scenarios, requiring Node.js v20 or newer.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the basic setup for a Vue 3 application using Vite SSG with Vue Router, defining a `createApp` export and configuring the build script.

import { ViteSSG } from 'vite-ssg'
import App from './App.vue'
import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  { path: '/', component: () => import('./pages/Home.vue') },
  { path: '/about', component: () => import('./pages/About.vue') },
]

export const createApp = ViteSSG(
  App,
  { routes, base: import.meta.env.BASE_URL },
  ({ app, router, routes, isClient, initialState }) => {
    // install plugins, register global components, etc.
    // app.use(somePlugin)
    // if (isClient) console.log('Client-side setup finished!')
  }
)

// package.json script update
// {
//   "scripts": {
//     "dev": "vite",
//     "build": "vite-ssg build"
//   }
// }

view raw JSON →