{"id":25736,"library":"htmlnano","title":"htmlnano","description":"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.","status":"active","version":"3.2.1","language":"javascript","source_language":"en","source_url":"git://github.com/maltsev/htmlnano","tags":["javascript","posthtml","posthtml-plugin","html","postproccessor","minifier","typescript"],"install":[{"cmd":"npm install htmlnano","lang":"bash","label":"npm"},{"cmd":"yarn add htmlnano","lang":"bash","label":"yarn"},{"cmd":"pnpm add htmlnano","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"CSS minification module (optional peer dependency)","package":"cssnano","optional":true},{"reason":"Required for CSS processing by cssnano (optional peer dependency)","package":"postcss","optional":true},{"reason":"JavaScript minification module (optional peer dependency)","package":"terser","optional":true},{"reason":"SVG minification module (optional peer dependency, required for SVG optimization)","package":"svgo","optional":true},{"reason":"Remove unused CSS (optional peer dependency, used in removeUnusedCss module since v3.2.0)","package":"purgecss","optional":true}],"imports":[{"note":"htmlnano v3 is ESM-only. CommonJS require() may work in some environments but is not officially supported.","wrong":"const htmlnano = require('htmlnano')","symbol":"default export","correct":"import htmlnano from 'htmlnano'"},{"note":"process returns a Promise. Callback style is not supported.","wrong":"htmlnano.process(html, options, preset, postHtmlOptions, callback)","symbol":"process","correct":"import htmlnano from 'htmlnano'; const result = await htmlnano.process(html, options)"},{"note":"Preset is a type export; use 'import type' for TypeScript.","wrong":"import { Preset } from 'htmlnano'","symbol":"Preset type","correct":"import type { Preset } from 'htmlnano'"}],"quickstart":{"code":"import htmlnano from 'htmlnano';\n\nconst html = '<div>  <p>Hello</p>  </div>';\nconst options = {\n  collapseWhitespace: 'conservative'\n};\n\ntry {\n  const result = await htmlnano.process(html, options);\n  console.log(result.html); // '<div><p>Hello</p></div>'\n} catch (err) {\n  console.error(err);\n}","lang":"typescript","description":"Basic usage of htmlnano to minify HTML with whitespace collapse option."},"warnings":[{"fix":"Review SVGO v4 migration guide; adjust SVG optimization options if needed.","message":"SVGO upgraded to v4 in htmlnano v3.0.0, which includes breaking changes. See https://svgo.dev/docs/migrations/migration-from-v3-to-v4/","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Replace callback with async/await or .then().","message":"Callback API removed in v2.0.0. Use Promise-based API.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use ESM import or upgrade to v2.1.6+.","message":"CommonJS import broken in v2.1.4 and v2.1.5, later fixed in v2.1.6? Check CHANGELOG.","severity":"gotcha","affected_versions":"2.1.4, 2.1.5"},{"fix":"Install types for optional peer dependencies (e.g., @types/cssnano) if needed.","message":"TypeScript 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.","severity":"gotcha","affected_versions":">=3.2.1"},{"fix":"Install purgecss as peer dependency if using removeUnusedCss.","message":"removeUnusedCss module now uses purgeCSS as default since v3.2.0, which requires purgecss peer dependency.","severity":"gotcha","affected_versions":">=3.2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install cssnano: npm install cssnano --save-dev","cause":"Optional peer dependency cssnano is not installed.","error":"Error: Cannot find module 'cssnano'"},{"fix":"Use import htmlnano from 'htmlnano' instead of require.","cause":"Using require() on ESM-only module, or importing incorrectly.","error":"TypeError: htmlnano.process is not a function"},{"fix":"Use 'safe' or 'max' (string) as preset, or omit to use default.","cause":"Invalid preset name passed to process function.","error":"Error: Preset must be one of: safe, max"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}