vite-plugin-html-pages
raw JSON →vite-plugin-html-pages (v1.6.8) is a minimal static site generation plugin for Vite that uses JavaScript functions returning HTML strings, built on the javascript-to-html library. It employs file-based routing akin to Next.js's pages router—supporting static, dynamic ([slug]), multiple parameters, catch-all, optional catch-all, index routes, and route groups. Unlike full-featured SSGs like Astro or Nuxt, this plugin provides a lightweight, framework-agnostic approach to generating static HTML without a component system or complex build pipeline. It automatically generates sitemap.xml, 404.html, RSS feeds, and includes dev server SSR rendering with fetch caching. Ships TypeScript types. Requires Vite >=5 and Node >=18. Release cadence: active maintenance with frequent updates.
Common errors
error Error: [vite-plugin-html-pages] Missing export 'generateStaticParams' in ... ↓
error TypeError: htmlPages is not a function ↓
error Error: Cannot find module 'javascript-to-html' ↓
error Error: [vite-plugin-html-pages] generateStaticParams must be a synchronous function ↓
Warnings
breaking Route file extension changed from .page.js to .ht.js in v1.0.0. ↓
breaking generateStaticParams must be synchronous starting from v1.2.0. Async functions cause build errors. ↓
deprecated The legacy route grouping syntax ( ) [parentheses] in filenames (e.g., (admin)/users.ht.js) is deprecated and may be removed in future versions. ↓
gotcha Plugin requires both 'javascript-to-html' and Vite as dependencies. Missing javascript-to-html causes runtime errors. ↓
gotcha Dev server rendering relies on React and ReactDOM >=18. If React is not installed, dev server fails silently. ↓
gotcha Catch-all routes ([...slug]) consume all path segments; ensure no overlapping static routes exist. ↓
Install
npm install vite-plugin-html-pages yarn add vite-plugin-html-pages pnpm add vite-plugin-html-pages Imports
- htmlPages wrong
import { htmlPages } from 'vite-plugin-html-pages'correctimport htmlPages from 'vite-plugin-html-pages' - defineConfig wrong
import { defineConfig } from 'vite-plugin-html-pages'correctimport { defineConfig } from 'vite' - fragment, html, body, h1, etc. wrong
import { fragment } from 'vite-plugin-html-pages'correctimport { fragment, html, body, h1 } from 'javascript-to-html' - generateStaticParams wrong
export const generateStaticParams = async () => { ... }correctexport function generateStaticParams() { ... }
Quickstart
// vite.config.js
import { defineConfig } from 'vite'
import htmlPages from 'vite-plugin-html-pages'
export default defineConfig({
plugins: [htmlPages()]
})
// src/index.ht.js
import { fragment, html, body, head, title, h1 } from 'javascript-to-html'
export default () => fragment(
'<!doctype html>',
html({lang: 'en'},
head(
title('My website')
),
body(
h1('Hello world')
)
)
)