{"id":20214,"library":"minify-html-webpack-plugin","title":"Minify HTML Webpack Plugin","description":"A webpack plugin that minifies HTML files using html-minifier after the webpack build. Version 1.1.7 supports webpack 2-5 and Node >= 6.0. It iterates through source directories recursively, copying and minifying all HTML files. Key features include search-and-replace before minification and an afterBuild option to run after webpack completes. The plugin is mainly used in PHP/Laravel projects to minify Blade-compiled views. Released sporadically, last update in 2021.","status":"active","version":"1.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/ashutoshSce/minify-html-webpack-plugin","tags":["javascript","minify","html","webpack","plugin","file","mix","php","laravel"],"install":[{"cmd":"npm install minify-html-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add minify-html-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add minify-html-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core library for HTML minification","package":"html-minifier","optional":false}],"imports":[{"note":"Package does not provide ESM exports; CommonJS require is required.","wrong":"import MinifyHtmlWebpackPlugin from 'minify-html-webpack-plugin';","symbol":"MinifyHtmlWebpackPlugin","correct":"const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');"},{"note":"Export is default, not named. Destructuring will yield undefined.","wrong":"const { MinifyHtmlWebpackPlugin } = require('minify-html-webpack-plugin');","symbol":"MinifyHtmlWebpackPlugin","correct":"const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');"},{"note":"Constructor requires at least `src` and `dest` options; otherwise it errors.","wrong":"new MinifyHtmlWebpackPlugin()","symbol":"MinifyHtmlWebpackPlugin","correct":"new MinifyHtmlWebpackPlugin({ src: '...', dest: '...' })"}],"quickstart":{"code":"// webpack.config.js\nconst path = require('path');\nconst MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js'\n  },\n  plugins: [\n    new MinifyHtmlWebpackPlugin({\n      src: path.resolve(__dirname, 'src/html'),\n      dest: path.resolve(__dirname, 'dist/html'),\n      rules: {\n        collapseBooleanAttributes: true,\n        collapseWhitespace: true,\n        removeAttributeQuotes: true,\n        removeComments: true,\n        minifyJS: true,\n        minifyCSS: true\n      }\n    })\n  ]\n};","lang":"javascript","description":"Basic config to minify HTML files from src/html to dist/html after webpack build."},"warnings":[{"fix":"Only use in production webpack config, not in development.","message":"Plugin does not work with Webpack Dev Server; it only runs on production builds.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set `afterBuild: true` if you require post-build processing.","message":"The `afterBuild` option was added in v1.1.4; prior versions always ran after build but now it defaults to false.","severity":"breaking","affected_versions":"<1.1.4"},{"fix":"No action needed unless you rely on the undocumented array of strings feature.","message":"The `searchAndReplace` option uses `search` and `replace` fields; `search` can be a string or regex.","severity":"deprecated","affected_versions":">=1.1.4"},{"fix":"Ensure `dest` is empty or has matching file structure.","message":"Plugin copies only files from `src` to `dest`; existing files in `dest` not overwritten unless matching source.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Refer to html-minifier documentation for valid rules.","message":"Html-minifier rules are passed directly; invalid rules may cause errors or be ignored silently.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install html-minifier --save-dev'","cause":"Missing dependency; html-minifier is not automatically installed.","error":"Error: Cannot find module 'html-minifier'"},{"fix":"Ensure each object in searchAndReplace has both 'search' and 'replace' fields.","cause":"searchAndReplace array entry missing 'search' or 'replace' property.","error":"TypeError: Cannot read property 'replace' of undefined"},{"fix":"Use 'const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');'","cause":"Using default import instead of require in CommonJS.","error":"MinifyHtmlWebpackPlugin is not a constructor"},{"fix":"Ensure src directory exists and path is correct.","cause":"Provided src path is invalid or does not exist.","error":"The 'src' directory does not exist"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}