Registry / devops / vite-plugin-minify-html

vite-plugin-minify-html

JSON →
library1.0.2jsnpmunverified

A Vite plugin to minify HTML output in production builds using html-minifier-terser. Version 1.0.2, stable, released via GitHub. Key differentiators: simple integration, full TypeScript support, leverages the robust html-minifier-terser under the hood for configurable minification (collapse whitespace, remove comments, etc.). Lightweight zero-config plugin with optional boolean or MinifyOptions argument. Requires Vite >=2.0.0 and Node >=14.0.0.

npm install vite-plugin-minify-html
INSTALL
IMPORT
SIG · VITE-PLUGIN-MINIFY
V
vite-plugin-minify-html
devopsjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import minifyHtml from 'vite-plugin-minify-html'
import { minifyHtml } from 'vite-plugin-minify-html'
The plugin is exported as default, not a named export. Named import will result in undefined.
MinifyOptions
import type { MinifyOptions } from 'vite-plugin-minify-html'
import { MinifyOptions } from 'vite-plugin-minify-html'
MinifyOptions is a TypeScript type, not a runtime value. Use type import to avoid bundling.
CommonJS require
const minifyHtml = require('vite-plugin-minify-html')
const { minifyHtml } = require('vite-plugin-minify-html')
CommonJS require works with default export in CJS context. Destructuring the default as named will fail.

Configures Vite to minify HTML with custom html-minifier-terser options.

// vite.config.js import { defineConfig } from 'vite'; import minifyHtml from 'vite-plugin-minify-html'; export default defineConfig({ plugins: [ minifyHtml({ collapseWhitespace: true, removeComments: true, minifyCSS: true, minifyJS: true, }), ], });
Debug
Known issues
gotchaPlugin only runs during production build by default. Dev server may not apply minification.
fix
Explicitly set `apply: 'build'` if needed, or use `apply: 'serve'` for dev server.
affects: >=1.0.0
gotchaOption `minifyHTML` in Vite v5 has been renamed to `minifyHtml` in this plugin. Potential confusion with built-in minification.
fix
Use this plugin and disable Vite's built-in minification if conflicts arise.
affects: >=1.0.0
deprecatedUsing `true` as argument (minifyHtml(true)) enables all defaults but may become deprecated in favor of an options object.
fix
Use an options object `{}` to be future-proof.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , require(...).default) is not a function
CommonJS project importing default export incorrectly.
fix
Use `const minifyHtml = require('vite-plugin-minify-html')` without destructuring.
Error: The plugin 'vite-plugin-minify-html' is not compatible with current Vite version. Expected "vite": ">=2.0.0"
Vite version is below 2.0.0.
fix
Upgrade Vite to ^2.0.0 or newer.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
viterequiredpeer dependency required for plugin to function
Agent activity
2 hits · last 30 days
node
2
Resources
vite-plugin-minify-html — npm install vite-plugin-minify-html · libregistry