{"id":20103,"library":"html-minimizer-webpack-plugin","title":"HTML Minimizer Webpack Plugin","description":"Webpack plugin (v6.0.0) that minifies HTML files using one of three engines: swc (Rust), html-minifier-terser (JavaScript, default), or @minify-html/node (Rust). Integrates into Webpack's optimization.minimizer pipeline. Requires Node >= 20.9.0 (v6), Webpack 5.1+. Provides TypeScript types. Releases: v6.0.0 (Mar 2026), v5.0.x (2025), v5.0.0 (Jan 2024, dropped Node <18.12.0). Differentiators: multi-engine support, deep Webpack integration, asset/resource compatibility.","status":"active","version":"6.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/webpack/html-minimizer-webpack-plugin","tags":["javascript","html","webpack","webpack-plugin","minimize","minimizer","minify","minifier","optimize","typescript"],"install":[{"cmd":"npm install html-minimizer-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add html-minimizer-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add html-minimizer-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; required to run as a Webpack plugin","package":"webpack","optional":false},{"reason":"Optional: needed if using swc minify engine","package":"@swc/html","optional":true},{"reason":"Optional: needed if using @minify-html/node minify engine","package":"@minify-html/node","optional":true}],"imports":[{"note":"CommonJS require works in Node, but ESM import is preferred. The package ships both ESM and CJS.","wrong":"const HtmlMinimizerPlugin = require('html-minimizer-webpack-plugin')","symbol":"HtmlMinimizerPlugin","correct":"import HtmlMinimizerPlugin from 'html-minimizer-webpack-plugin'"},{"note":"swcMinify and swcMinifyFragment are static properties on the default export, not named exports. Since v5.","wrong":"import { swcMinify } from 'html-minimizer-webpack-plugin'","symbol":"swcMinify","correct":"import HtmlMinimizerPlugin from 'html-minimizer-webpack-plugin';\nconst { swcMinify } = HtmlMinimizerPlugin;"},{"note":"Available since v4.3.0. Also accessed via static property.","wrong":"import { swcMinifyFragment } from 'html-minimizer-webpack-plugin'","symbol":"swcMinifyFragment","correct":"HtmlMinimizerPlugin.swcMinifyFragment"}],"quickstart":{"code":"// webpack.config.js (CommonJS)\nconst HtmlMinimizerPlugin = require('html-minimizer-webpack-plugin');\n\nmodule.exports = {\n  optimization: {\n    minimize: true,\n    minimizer: [\n      new HtmlMinimizerPlugin({\n        minimizerOptions: {\n          // html-minifier-terser options\n          collapseWhitespace: true,\n          removeComments: true,\n        },\n      }),\n    ],\n  },\n};","lang":"javascript","description":"Basic configuration using default html-minifier-terser engine with custom options. Requires optimization.minimize: true."},"warnings":[{"fix":"Upgrade Node.js to >=20.9.0 or stay on v5.x (requires Node >=18.12.0).","message":"Node.js >= 20.9.0 required, dropped support for older versions.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Upgrade Node.js to >=18.12.0 or use v4.x (Node 14+).","message":"Node.js >= 18.12.0 required in v5.0.0.","severity":"breaking","affected_versions":">=5.0.0 <6.0.0"},{"fix":"Add optimization.minimize: true to webpack config to enable minification in non-production modes.","message":"HTML is only minimized in production mode by default. In development, set optimization.minimize: true explicitly.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Ensure your HTML files are emitted as assets (e.g., via copy-webpack-plugin or html-webpack-plugin) before they reach the minimizer.","message":"The plugin processes only assets emitted by other plugins like copy-webpack-plugin or html-webpack-plugin; it does not handle inline HTML in JavaScript.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Pass the static property, e.g., minify: HtmlMinimizerPlugin.swcMinify.","message":"When using @swc/html, minify option must be HtmlMinimizerPlugin.swcMinify or swcMinifyFragment; using a string 'swc' will not work.","severity":"gotcha","affected_versions":">=5.0.0"},{"fix":"Use 'options' property for minimizer options in v6; check your TypeScript strictness.","message":"The option 'minimizerOptions' is incorrectly typed in some TypeScript versions; use 'options' instead (v5+).","severity":"deprecated","affected_versions":">=5.0.0 <6.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Change to const HtmlMinimizerPlugin = require('html-minimizer-webpack-plugin');","cause":"Using named import instead of default import in CommonJS.","error":"Error: HtmlMinimizerPlugin is not a constructor"},{"fix":"Make sure you have installed html-minifier-terser (auto-installed) or specify minify option.","cause":"Plugin configured without proper minimizer function; default engine not found.","error":"TypeError: Cannot read properties of undefined (reading 'minify')"},{"fix":"Run npm install @swc/html --save-dev","cause":"Missing optional dependency @swc/html when using swc minify.","error":"Module not found: Error: Can't resolve '@swc/html'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}