{"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,"search_vec":"'/node':29 '18.12.0':57 '20.9.0':39 '2024':54 '2025':51 '2026':49 '5.1':42 'asset/resource':66 'compat':67 'deep':63 'default':24 'differenti':58 'drop':55 'engin':16,61 'file':11 'html':1,10,20,28,69 'html-minifier-ters':19 'integr':31,65 'jan':53 'javascript':23,68 'mar':48 'minifi':9,21,27,76,77 'minify-html':26 'minim':2,74,75 'multi':60 'multi-engin':59 'node':38,56 'one':13 'optim':78 'optimization.minimizer':35 'pipelin':36 'plugin':4,6,73 'provid':43 'releas':46 'requir':37 'rust':18,30 'support':62 'swc':17 'terser':22 'three':15 'type':45 'typescript':44,79 'use':12 'v5.0.0':52 'v5.0.x':50 'v6':40 'v6.0.0':7,47 'webpack':3,5,33,41,64,70,72 'webpack-plugin':71","created_at":"2026-04-25T11:21:20.508642+00:00","updated_at":"2026-04-25T11:21:20.508642+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/webpack/html-minimizer-webpack-plugin","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/html-minimizer-webpack-plugin","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}