Registry / devops / html-minifier-webpack-plugin

html-minifier-webpack-plugin

JSON →
library2.2.3jsnpmunverified

A Webpack plugin that minimizes HTML files using HTMLMinifier during the build process. Currently at version 2.2.3, it integrates directly into Webpack's plugin system, applying HTMLMinifier options to all HTML files processed by loaders such as html-loader. It supports custom HTMLMinifier configuration and works with Webpack 4+. Compared to alternatives like html-webpack-plugin's minification, this plugin is more lightweight and focused solely on minimization.

npm install html-minifier-webpack-plugin
INSTALL
IMPORT
SIG · HTML-MINIFIER-WEBP
H
html-minifier-webpack-plugin
devopsjavascriptv2.2.3
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.

HtmlMinifierPlugin
import HtmlMinifierPlugin from 'html-minifier-webpack-plugin'
const HtmlMinifierPlugin = require('html-minifier-webpack-plugin');
ESM default import works; CommonJS require is also supported.
HtmlMinifierPlugin
const HtmlMinifierPlugin = require('html-minifier-webpack-plugin');
const { HtmlMinifierPlugin } = require('html-minifier-webpack-plugin');
Plugin is exported as default, not a named export. Avoid destructuring require.
HtmlMinifierPlugin
import HtmlMinifierPlugin from 'html-minifier-webpack-plugin'
import { HtmlMinifierPlugin } from 'html-minifier-webpack-plugin'
Named import will result in undefined; use default import.

Demonstrates basic usage with ESM import and HTMLMinifier minification options.

// webpack.config.js import HtmlMinifierPlugin from 'html-minifier-webpack-plugin'; export default { module: { rules: [ { test: /\.html$/, use: ['file-loader?name=[name].html', 'extract-loader', 'html-loader'] } ] }, plugins: [ new HtmlMinifierPlugin({ removeComments: true, collapseWhitespace: true, minifyCSS: true, minifyJS: true }) ] };
Debug
Known issues
deprecatedThe plugin may not receive frequent updates; consider using html-webpack-plugin's built-in minification for Webpack 5.
fix
If using Webpack 5, prefer setting optimization.minimize in webpack config or use html-webpack-plugin with minification enabled.
affects: >=2.0
gotchaPlugin requires html-minifier as a peer dependency; missing it will cause runtime errors.
fix
Run 'npm install html-minifier --save-dev' to install peer dependency.
affects: >=2.0
gotchaPlugin does not work with html-webpack-plugin's hooks; may cause double processing or conflicts.
fix
Use either this plugin or html-webpack-plugin's minification, not both.
affects: >=2.0
Errors
Common errors & fixes
Error: Cannot find module 'html-minifier'
Missing peer dependency html-minifier.
fix
npm install html-minifier --save-dev
TypeError: HtmlMinifierPlugin is not a constructor
Incorrect import (named instead of default).
fix
Use default import: import HtmlMinifierPlugin from 'html-minifier-webpack-plugin'
Module not found: Error: Can't resolve 'html-minifier'
html-minifier not installed or not resolvable.
fix
Ensure html-minifier is in node_modules; install it via npm.
Upgrade
Version history
2.2.3latest on npm
Audit
Dependencies
html-minifierrequiredCore dependency for HTML minimization logic; must be installed separately as a peer dependency.
webpackrequiredPeer dependency; plugin requires Webpack 4 or 5 to function.
Agent activity
6 hits · last 30 days
node
6
Resources
html-minifier-webpack-plugin — npm install html-minifier-webpack-plugin · libregistry