Registry / devops / rollup-plugin-minify-html

rollup-plugin-minify-html

JSON →
library1.1.1jsnpmunverified

A Rollup plugin that minifies HTML files using html-minifier during the build process. Version 1.1.1 is the latest stable release. It supports per-target minification options, global minifier options, and a configurable hook. The plugin can minify HTML files in the output directory automatically. Currently no major updates are anticipated.

npm install rollup-plugin-minify-html
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-MINI
R
rollup-plugin-minify-html
devopsjavascriptv1.1.1
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.

minifyHTML
import { minifyHTML } from 'rollup-plugin-minify-html'
import minifyHTML from 'rollup-plugin-minify-html'
Requires named import; default import is not available.
minifyHTML (CommonJS)
const { minifyHTML } = require('rollup-plugin-minify-html')
const minifyHTML = require('rollup-plugin-minify-html')
CommonJS users must destructure the named export.
minifyHTML (TypeScript)
import { minifyHTML } from 'rollup-plugin-minify-html'
Type definitions are not shipped; may need to declare module or use with '// @ts-ignore'.

Configures rollup-plugin-minify-html to minify an HTML file with per-target and global minifier options.

// rollup.config.js import { minifyHTML } from 'rollup-plugin-minify-html'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'iife', }, plugins: [ minifyHTML({ targets: [ { src: 'public/index.html', dest: 'dist/index.html', minifyOptions: { minifyJS: true } } ], minifierOptions: { collapseWhitespace: true, minifyCSS: true, minifyJS: false, minifyURLs: true, }, }), ], };
Debug
Known issues
gotchaThe 'targets' array requires both 'src' and 'dest' properties; missing either will cause runtime error.
fix
Ensure each target object has 'src' and 'dest' defined.
affects: >=1.0.0
gotchaGlobal 'minifierOptions' are overridden by per-target 'minifyOptions'; order of precedence may surprise if mixed.
fix
Explicitly set desired options in each target if overriding globally.
affects: >=1.0.0
gotchaThe 'hook' default is 'buildEnd'; changing to 'generateBundle' may cause HTML files not found if output dir hasn't been created.
fix
Use 'buildEnd' or ensure output directory exists when using other hooks.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-minify-html'
Package not installed or peer dependency rollup version mismatch.
fix
Run 'npm install rollup-plugin-minify-html --save-dev' and ensure rollup >=2 <5 is installed.
TypeError: targets is not iterable
The 'targets' option is not provided or is not an array.
fix
Pass an array to 'targets', e.g., targets: [{ src: '...', dest: '...' }].
Error: Minify options must be an object
Invalid 'minifierOptions' or 'minifyOptions' value (e.g., passing a string).
fix
Ensure 'minifierOptions' and per-target 'minifyOptions' are plain objects.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
rolluprequiredpeer dependency, plugin designed for Rollup >=2 <5
html-minifierrequiredruntime dependency for minifying HTML
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-minify-html — npm install rollup-plugin-minify-html · libregistry