A Metalsmith plugin that minifies HTML files using kangax/html-minifier. Current stable version is 4.0.1, compatible with Node.js >=8. It offers built-in defaults that aggressively optimize HTML (e.g. collapsing whitespace, removing comments, removing attribute quotes) which may break conditional comments or whitespace-sensitive layouts. Unlike generic HTML minifiers, it integrates directly into the Metalsmith build pipeline, supporting glob patterns and custom minifier options. Release cadence is low; no major updates since 2019.
npm install metalsmith-html-minifierNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows Metalsmith setup with html-minifier plugin, custom glob pattern, and explicit minifier options. Demonstrates disabling certain defaults to avoid breaking HTML.
Set minifierOptions.removeComments: false and minifierOptions.collapseWhitespace: false if you need to preserve them.
Always use a glob pattern like `'**/*.html'` or an array of globs.
Consider switching to an alternative html-minifier that is actively maintained (e.g., html-minifier-terser or using a different build tool).
Always specify a restrictive pattern like `['**/*.html', '!**/_*/**']` to exclude partials.
Use `const htmlMinifier = require('metalsmith-html-minifier');` instead of `import htmlMinifier from 'metalsmith-html-minifier';`.Use `Metalsmith(__dirname).use(htmlMinifier())` not `Metalsmith(__dirname).use(htmlMinifier({})())`.Run `npm install metalsmith-html-minifier --save` which will install the required dependency automatically.