Registry / devops / metalsmith-html-minifier-multimatch

metalsmith-html-minifier-multimatch

JSON →
library2.2.0jsnpmunverified

A Metalsmith plugin that minifies HTML files using kangax/html-minifier. Version 2.2.0 is the current stable release, with a low update cadence (last updated in 2018). Key differentiators: it integrates seamlessly with Metalsmith build pipelines, supports glob patterns for file selection, and provides sensible defaults while allowing full configuration of html-minifier options. It enables several optimizations by default (e.g., collapsing whitespace, removing comments), which users should disable explicitly if undesired. The plugin is lightweight with no runtime dependencies beyond metalsmith and html-minifier.

npm install metalsmith-html-minifier-multimatch
INSTALL
IMPORT
SIG · METALSMITH-HTML-MI
M
metalsmith-html-minifier-multimatch
devopsjavascriptv2.2.0
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)
import htmlMinifier from 'metalsmith-html-minifier'
const htmlMinifier = require('metalsmith-html-minifier')
Default import is the plugin function. CJS require() also works but ESM is preferred for new projects.
Metalsmith
import Metalsmith from 'metalsmith'
Metalsmith is a separate package, needed to use this plugin.
Options interface
import type { Options } from 'html-minifier'
TypeScript users can import the options type from html-minifier for type safety.

This example shows how to use the plugin with a custom glob pattern and minifier options to disable comment removal while enabling whitespace collapse.

import Metalsmith from 'metalsmith'; import htmlMinifier from 'metalsmith-html-minifier'; Metalsmith(__dirname) .use(htmlMinifier('*.html', { removeComments: false, collapseWhitespace: true, })) .build((err) => { if (err) throw err; console.log('Build complete!'); });
Debug
Known issues
deprecatedhtml-minifier is no longer actively maintained; consider using html-minifier-terser or other alternatives.
fix
Evaluate newer minification libraries like html-minifier-terser.
affects: >=1.0.0
gotchaCertain optimizations are enabled by default (e.g., collapseBooleanAttributes, removeComments) which may break functionality like conditional comments or AngularJS directives.
fix
Explicitly set unwanted options to false, e.g., { removeComments: false }.
affects: >=0.1.0
gotchaThe glob pattern is passed directly to multimatch; incorrect patterns may result in no files being minified.
fix
Test glob patterns with a small set of files first or use a clear pattern like '**/*.html'.
affects: >=2.0.0
breakingVersion 2.0.0 changed the API from accepting an options object as first argument to requiring a glob string first.
fix
Update calls from .use(htmlMinifier({...})) to .use(htmlMinifier('**/*.html', {...})).
affects: >=2.0.0 <3.0.0
gotchaThe plugin operates on the file contents after other plugins; ordering matters if other plugins modify HTML.
fix
Place this plugin after any plugin that may alter HTML content (e.g., template engines).
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: htmlMinifier is not a function
Using ESM import when the package is imported as default but the module system is misconfigured.
fix
Ensure Node.js version supports ESM or use require() syntax: const htmlMinifier = require('metalsmith-html-minifier');
Error: No files matched pattern '*.html'
The glob pattern does not match any files in the Metalsmith source directory.
fix
Use a more inclusive pattern like '**/*.html' or verify the source directory path.
Unhandled rejection: Error: Cannot find module 'html-minifier'
Missing dependency html-minifier.
fix
Run npm install html-minifier --save.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
metalsmithrequiredPeer dependency – the plugin is designed to be used as a Metalsmith plugin.
html-minifierrequiredCore dependency – provides the HTML minification logic.
Agent activity
2 hits · last 30 days
node
2
Resources
metalsmith-html-minifier-multimatch — npm install metalsmith-html-minifier-multimatch · libregistry