Registry / devops / gulp-html-minimizer

gulp-html-minimizer

JSON →
library2.0.1jsnpmunverified

Gulp plugin (v2.0.1, stable) that minifies HTML using the actively maintained HTMLMinifier fork (html-minifier-terser). It wraps HTMLMinifier's full option set — including collapseWhitespace, minifyCSS, minifyJS, and custom attribute handling — into a streaming Gulp pipeline. Differentiates from alternatives like gulp-htmlmin by using the terser-based fork (active maintenance, no known CVEs). Lightweight; zero runtime peer deps beyond Gulp itself.

npm install gulp-html-minimizer
INSTALL
IMPORT
SIG · GULP-HTML-MINIMIZE
G
gulp-html-minimizer
devopsjavascriptv2.0.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.

default (function)
const htmlMinimizer = require('gulp-html-minimizer'); // or ESM: import htmlMinimizer from 'gulp-html-minimizer';
const htmlMinimizer = require('gulp-html-minimizer').default;
The package exports a single function directly (CommonJS default export). Do not destructure.
gulp-html-minimizer
const gulp = require('gulp'); const htmlMinimizer = require('gulp-html-minimizer');
import { htmlMinimizer } from 'gulp-html-minimizer';
Use CommonJS require (default). Named import is incorrect.
PluginOptions
import type { PluginOptions } from 'gulp-html-minimizer';
TypeScript: import type for plugin options (starting from v1.x).

Shows a Gulp task that minifies HTML files with whitespace collapse and CSS/JS minification.

const gulp = require('gulp'); const htmlMinimizer = require('gulp-html-minimizer'); exports.minify = function() { return gulp.src('src/*.html') .pipe(htmlMinimizer({ collapseWhitespace: true, removeComments: true, minifyCSS: true, minifyJS: true })) .pipe(gulp.dest('dist')); };
Debug
Known issues
gotchaOptions are disabled by default; collapseWhitespace and removeComments must be explicitly enabled to see size reduction.
fix
Set options like collapseWhitespace: true in the plugin options.
affects: *
gotchaThe 'html-minifier-terser' fork is used, not the original 'html-minifier'. Options are identical but behavior may differ subtly.
fix
Refer to html-minifier-terser documentation for option details.
affects: >=2.0.0
breakingRequires Node >=6.17.1. Older Node versions will fail to install or run.
fix
Upgrade Node to >=6.17.1 or use an older version of the plugin (e.g., 1.x).
affects: >=2.0.0
gotchaminifyCSS and minifyJS can be objects or functions, not just booleans. Using true picks defaults, but advanced config is possible.
fix
Pass an object (e.g., minifyCSS: { level: 2 }) or function for custom minification.
affects: *
deprecatedPackage keywords list 'htmlminifier' but that library is unmaintained; the fork 'html-minifier-terser' is the active one.
fix
No action needed; the plugin uses the fork. Just be aware of the change.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: htmlMinimizer is not a function
Using destructured import (e.g., import { htmlMinimizer } from ...) instead of default import.
fix
Use: const htmlMinimizer = require('gulp-html-minimizer'); or ESM: import htmlMinimizer from 'gulp-html-minimizer';
Error: Cannot find module 'gulp-html-minimizer'
Package not installed or module resolution misconfigured.
fix
Run: npm install --save-dev gulp-html-minimizer
ReferenceError: gulp is not defined
Gulp is not imported or installed.
fix
Install Gulp: npm install --save-dev gulp, then require it.
Error: HTML parsing error: unexpected token
Invalid HTML or missing caseSensitive option for custom tags.
fix
Enable caseSensitive: true if using non-standard HTML tags.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
gulprequiredRequires Gulp as peer dependency for streaming plugin functionality
html-minifier-terserrequiredCore HTML minification engine (active fork of html-minifier)
Agent activity
4 hits · last 30 days
node
4
Resources
gulp-html-minimizer — npm install gulp-html-minimizer · libregistry