Registry / devops / gulp-html-minifier2

gulp-html-minifier2

JSON →
library1.1.11jsnpmunverified

A Gulp plugin wrapper around the html-minifier library for minifying HTML files. Version 1.1.11 is the latest stable release as of 2021, with minimal updates since 2016. It supports collapsing whitespace, removing comments, and other html-minifier options. The plugin adds convenience features like `ignorePath` to strip prefixes from file paths and `env` option to disable minification in development. It is a fork of the original gulp-html-minifier, providing compatibility with newer Gulp versions.

npm install gulp-html-minifier2
INSTALL
IMPORT
SIG · GULP-HTML-MINIFIER
G
gulp-html-minifier2
devopsjavascriptv1.1.11
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.

gulp-html-minifier2
const htmlmin = require('gulp-html-minifier2');
import htmlmin from 'gulp-html-minifier2';
The package does not export ESM, so use CommonJS require.
default export
const htmlmin = require('gulp-html-minifier2');
const { htmlmin } = require('gulp-html-minifier2');
The package exports a single function, not a named export.
TypeScript usage
const htmlmin = require('gulp-html-minifier2'); // No type definitions; use @types/gulp-html-minifier2 if available
import htmlmin from 'gulp-html-minifier2';
No official TypeScript types; use require and possibly install community types.

Basic Gulp task that minifies HTML files from src to dist using html-minifier with collapsed whitespace.

const gulp = require('gulp'); const htmlmin = require('gulp-html-minifier2'); gulp.task('minify', function() { return gulp.src('./src/*.html') .pipe(htmlmin({collapseWhitespace: true})) .pipe(gulp.dest('./dist')); });
Debug
Known issues
gotchaPackage is a fork and may have slight behavioral differences from the original gulp-html-minifier.
fix
Check documentation for extra options like ignorePath and env.
affects: >=1.0.0
deprecatedThe underlying html-minifier library is no longer actively maintained; consider alternatives like html-minifier-terser.
fix
Migrate to gulp-htmlmin or another actively maintained plugin that uses a maintained minifier.
affects: >=1.0.0
gotchaThe 'env' option in options disables minification entirely; ensure it is not accidentally set to 'development' in production.
fix
Do not pass {env: 'development'} in production tasks.
affects: >=1.0.0
gotchaThe 'ignorePath' option strips the given path prefix from relative file paths; may cause unexpected output paths if not used correctly.
fix
Verify the expected output paths when using ignorePath.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'gulp-html-minifier2'
Package not installed
fix
Run 'npm install gulp-html-minifier2 --save-dev'
TypeError: htmlmin is not a function
Incorrect import: using named destructuring
fix
Change to 'const htmlmin = require('gulp-html-minifier2');'
Error: Task 'minify' is not a function
Gulp 4 requires a returned stream
fix
Add 'return' before gulp.src()
Upgrade
Version history
1.1.11latest on npm
Audit
Dependencies
html-minifierrequiredcore minification engine
plugin-errorrequiredGulp plugin error handling
through2requiredstream transformation
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
gulp-html-minifier2 — npm install gulp-html-minifier2 · libregistry