Registry / devops / htmlminiiiiii

htmlminiiiiii

JSON →
library3.5.21jsnpmunverified

HTMLMinifier is a highly configurable, well-tested JavaScript HTML minifier that reduces HTML size by removing whitespace, comments, redundant attributes, and optimizing code structure. Current stable version is 4.0.0 (as of 2023), with irregular release cadence. It offers extensive customization options (30+), supports CLI and Node.js API, and consistently outperforms alternatives like minimize and htmlcompressor in benchmarks. Suitable for both development and production builds.

npm install htmlminiiiiii
INSTALL
IMPORT
SIG · HTMLMINIIIIII
H
htmlminiiiiii
devopsjavascriptv3.5.21
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.

minify
const minify = require('html-minifier').minify;
const minify = require('html-minifier');
Default export is an object with minify function; direct require returns the object.
minify
import { minify } from 'html-minifier';
import minify from 'html-minifier';
ESM named import from v4; default import is not available.
Options
import type { Options } from 'html-minifier';
TypeScript users should import the Options type for type-safe configuration.

Demonstrates basic HTML minification with key options enabled, showing how to remove unnecessary whitespace, quotes, comments, and minify inline CSS/JS.

const { minify } = require('html-minifier'); const result = minify('<p title=" blah " style="margin: 0 0 0 30px"> foo </p>', { collapseWhitespace: true, removeAttributeQuotes: true, removeComments: true, minifyCSS: true, minifyJS: true }); console.log(result);
Debug
Known issues
breakingVersion 4.0 changed the API: minify is no longer a default export but a named export from the module.
fix
Use import { minify } from 'html-minifier' or const { minify } = require('html-minifier').
affects: >=4.0.0
breakingVersion 3.0 dropped support for Node 0.12 and below; requires Node >=4.
fix
Upgrade Node to v4 or later.
affects: >=3.0.0
deprecatedThe `removeComments` option is deprecated; use `removeComments: true` in `minify` options but it may be removed in future.
fix
Continue using the option until migration to alternative.
affects: >=3.0.0
gotchaThe `processScripts` option requires explicit array of script types to process; leaving it empty means no scripts are minified.
fix
Specify an array like `['text/html', 'text/ng-template']` to process template scripts.
affects: <=4.0.0
gotchaWhen using `minifyCSS` or `minifyJS`, ensure the corresponding dependencies (clean-css, terser) are installed; they are optional peer dependencies.
fix
Install required dependencies: npm install clean-css terser.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: htmlminifier__WEBPACK_IMPORTED_MODULE_0___default(...) is not a function
Using default import with ESM instead of named import in version 4+.
fix
Replace `import htmlminifier from 'html-minifier'` with `import { minify } from 'html-minifier'`.
Error: Cannot find module 'clean-css'
Missing optional dependency for minifyCSS option.
fix
Run `npm install clean-css` and add it to your project.
Error: Cannot find module 'terser'
Missing optional dependency for minifyJS option.
fix
Run `npm install terser` and add it to your project.
ValidationError: 'collapseWhitespace' is not a recognized option
Typo in option name; correct is 'collapseWhitespace' (common misspelling: collapeWhitespace).
fix
Use the correct option name `collapseWhitespace`.
Upgrade
Version history
3.5.21latest on npm
Audit
Dependencies
clean-cssoptionalRequired for CSS minification within HTML.
relateurloptionalUsed for URL rewriting (e.g., relative paths).
terseroptionalRequired for inline script minification.
Agent activity
2 hits · last 30 days
node
2
Resources
htmlminiiiiii — npm install htmlminiiiiii · libregistry