vite-plugin-html-minifier-terser

raw JSON →
3.8.0 verified Mon Apr 27 auth: no javascript

Vite plugin that minifies HTML output during the build phase using html-minifier-terser. Version 3.8.0 released in 2025, maintained actively, ships TypeScript types. Configure all html-minifier-terser options directly. Differentiates from similar plugins by using the terser fork of html-minifier for better compatibility with modern HTML5. Commonly used to reduce HTML file size by removing whitespace, quotes, and comments.

error Error: Cannot find module 'vite-plugin-html-minifier-terser'
cause Package not installed or missing dependency.
fix
Run 'npm install vite-plugin-html-minifier-terser --save-dev'
error TypeError: htmlMinifierTerser is not a function
cause Using named import instead of default import.
fix
Use 'import htmlMinifierTerser from ...' (no curly braces)
gotcha Plugin only minifies during build, not in dev mode.
fix Use for production builds only; no workaround for dev.
gotcha Options are passed directly to html-minifier-terser; refer to its docs.
fix Check html-minifier-terser documentation for all valid options.
npm install vite-plugin-html-minifier-terser
yarn add vite-plugin-html-minifier-terser
pnpm add vite-plugin-html-minifier-terser

Configures vite-plugin-html-minifier-terser with common minification options in Vite's config file.

// vite.config.ts
import { defineConfig } from 'vite';
import htmlMinifierTerser from 'vite-plugin-html-minifier-terser';

export default defineConfig({
  plugins: [
    htmlMinifierTerser({
      removeComments: true,
      collapseWhitespace: true,
      removeAttributeQuotes: true,
      minifyCSS: true,
      minifyJS: true,
    }),
  ],
});