Registry / web-framework / htmlnano

htmlnano

JSON →
library3.2.1jsnpmunverified

Modular HTML minifier built on PostHTML, version 3.2.1 (stable). Released occasionally, with recent versions focusing on TypeScript migration, performance improvements, and edge case fixes. Key differentiators: modular architecture allowing selective enabling/disabling of minification modules, presets (safe, max), and extensive configuration options. Compared to html-minifier-terser or minify-html, htmlnano offers deeper integration with PostHTML ecosystem and supports advanced features like CSS/JS minification via optional peer dependencies (cssnano, terser). Includes CLI tool and TypeScript types.

npm install htmlnano
INSTALL
IMPORT
SIG · HTMLNANO
H
htmlnano
web-frameworkjavascriptv3.2.1
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 export
import htmlnano from 'htmlnano'
const htmlnano = require('htmlnano')
htmlnano v3 is ESM-only. CommonJS require() may work in some environments but is not officially supported.
process
import htmlnano from 'htmlnano'; const result = await htmlnano.process(html, options)
htmlnano.process(html, options, preset, postHtmlOptions, callback)
process returns a Promise. Callback style is not supported.
Preset type
import type { Preset } from 'htmlnano'
import { Preset } from 'htmlnano'
Preset is a type export; use 'import type' for TypeScript.

Basic usage of htmlnano to minify HTML with whitespace collapse option.

import htmlnano from 'htmlnano'; const html = '<div> <p>Hello</p> </div>'; const options = { collapseWhitespace: 'conservative' }; try { const result = await htmlnano.process(html, options); console.log(result.html); // '<div><p>Hello</p></div>' } catch (err) { console.error(err); }
htmlnano --version
Debug
Known issues
breakingSVGO upgraded to v4 in htmlnano v3.0.0, which includes breaking changes. See https://svgo.dev/docs/migrations/migration-from-v3-to-v4/
fix
Review SVGO v4 migration guide; adjust SVG optimization options if needed.
affects: >=3.0.0 <4.0.0
deprecatedCallback API removed in v2.0.0. Use Promise-based API.
fix
Replace callback with async/await or .then().
affects: >=2.0.0
gotchaCommonJS import broken in v2.1.4 and v2.1.5, later fixed in v2.1.6? Check CHANGELOG.
fix
Use ESM import or upgrade to v2.1.6+.
affects: 2.1.4, 2.1.5
gotchaTypeScript types removed peer dependency type imports in v3.2.1 to avoid requiring peer dep types to be installed, but users may need to install types separately for optional modules.
fix
Install types for optional peer dependencies (e.g., @types/cssnano) if needed.
affects: >=3.2.1
gotcharemoveUnusedCss module now uses purgeCSS as default since v3.2.0, which requires purgecss peer dependency.
fix
Install purgecss as peer dependency if using removeUnusedCss.
affects: >=3.2.0
Errors
Common errors & fixes
Error: Cannot find module 'cssnano'
Optional peer dependency cssnano is not installed.
fix
Install cssnano: npm install cssnano --save-dev
TypeError: htmlnano.process is not a function
Using require() on ESM-only module, or importing incorrectly.
fix
Use import htmlnano from 'htmlnano' instead of require.
Error: Preset must be one of: safe, max
Invalid preset name passed to process function.
fix
Use 'safe' or 'max' (string) as preset, or omit to use default.
Upgrade
Version history
3.2.1latest on npm
Audit
Dependencies
cssnanooptionalCSS minification module (optional peer dependency)
postcssoptionalRequired for CSS processing by cssnano (optional peer dependency)
terseroptionalJavaScript minification module (optional peer dependency)
svgooptionalSVG minification module (optional peer dependency, required for SVG optimization)
purgecssoptionalRemove unused CSS (optional peer dependency, used in removeUnusedCss module since v3.2.0)
Agent activity
4 hits · last 30 days
node
4
Resources
htmlnano — npm install htmlnano · libregistry