Registry / devops / minify-html-webpack-plugin

minify-html-webpack-plugin

JSON →
library1.1.7jsnpmunverified

A webpack plugin that minifies HTML files using html-minifier after the webpack build. Version 1.1.7 supports webpack 2-5 and Node >= 6.0. It iterates through source directories recursively, copying and minifying all HTML files. Key features include search-and-replace before minification and an afterBuild option to run after webpack completes. The plugin is mainly used in PHP/Laravel projects to minify Blade-compiled views. Released sporadically, last update in 2021.

npm install minify-html-webpack-plugin
INSTALL
IMPORT
SIG · MINIFY-HTML-WEBPAC
M
minify-html-webpack-plugin
devopsjavascriptv1.1.7
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

MinifyHtmlWebpackPlugin
const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');
import MinifyHtmlWebpackPlugin from 'minify-html-webpack-plugin';
Package does not provide ESM exports; CommonJS require is required.
MinifyHtmlWebpackPlugin
const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');
const { MinifyHtmlWebpackPlugin } = require('minify-html-webpack-plugin');
Export is default, not named. Destructuring will yield undefined.
MinifyHtmlWebpackPlugin
new MinifyHtmlWebpackPlugin({ src: '...', dest: '...' })
new MinifyHtmlWebpackPlugin()
Constructor requires at least `src` and `dest` options; otherwise it errors.

Basic config to minify HTML files from src/html to dist/html after webpack build.

// webpack.config.js const path = require('path'); const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, plugins: [ new MinifyHtmlWebpackPlugin({ src: path.resolve(__dirname, 'src/html'), dest: path.resolve(__dirname, 'dist/html'), rules: { collapseBooleanAttributes: true, collapseWhitespace: true, removeAttributeQuotes: true, removeComments: true, minifyJS: true, minifyCSS: true } }) ] };
Debug
Known issues
gotchaPlugin does not work with Webpack Dev Server; it only runs on production builds.
fix
Only use in production webpack config, not in development.
affects: >=1.0.0
breakingThe `afterBuild` option was added in v1.1.4; prior versions always ran after build but now it defaults to false.
fix
Set `afterBuild: true` if you require post-build processing.
affects: <1.1.4
deprecatedThe `searchAndReplace` option uses `search` and `replace` fields; `search` can be a string or regex.
fix
No action needed unless you rely on the undocumented array of strings feature.
affects: >=1.1.4
gotchaPlugin copies only files from `src` to `dest`; existing files in `dest` not overwritten unless matching source.
fix
Ensure `dest` is empty or has matching file structure.
affects: >=1.0.0
gotchaHtml-minifier rules are passed directly; invalid rules may cause errors or be ignored silently.
fix
Refer to html-minifier documentation for valid rules.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'html-minifier'
Missing dependency; html-minifier is not automatically installed.
fix
Run 'npm install html-minifier --save-dev'
TypeError: Cannot read property 'replace' of undefined
searchAndReplace array entry missing 'search' or 'replace' property.
fix
Ensure each object in searchAndReplace has both 'search' and 'replace' fields.
MinifyHtmlWebpackPlugin is not a constructor
Using default import instead of require in CommonJS.
fix
Use 'const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');'
The 'src' directory does not exist
Provided src path is invalid or does not exist.
fix
Ensure src directory exists and path is correct.
Upgrade
Version history
1.1.7latest on npm
Audit
Dependencies
html-minifierrequiredCore library for HTML minification
Agent activity
2 hits · last 30 days
node
2
Resources
minify-html-webpack-plugin — npm install minify-html-webpack-plugin · libregistry