Plugin that simplifies creation of HTML files to serve your webpack bundles, especially useful for bundles with hashed filenames. Current stable version: 5.6.7. The plugin generates an HTML file for you, or you can provide your own template using lodash templates. It injects all webpack bundles into the HTML and supports a rich event system for extensibility. Key differentiators: zero-config setup, hooks for custom plugins, and support for multiple HTML files. Alternatives like HtmlBundlerPlugin or script-ext-html-webpack-plugin build on top of this. Actively maintained with frequent releases.
npm install html-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
Basic webpack config using HtmlWebpackPlugin with a custom template and output filename.
If using webpack 4, install html-webpack-plugin@4. For webpack 5, ensure webpack ^5.20.0.
Set 'inject' to 'head' or 'body' explicitly, or use a custom template with manual injection.
Migrate to using 'htmlWebpackPluginAlterAssetTags' or other new hooks.
Be explicit with 'chunks' option to avoid unexpected bundles. Use 'excludeChunks' to exclude specific ones.
Configure 'minify' option or set to false. Known issue: removing quotes or collapsing boolean attributes may break certain elements.
Ensure 'template' option points to an existing file. Use absolute path or relative to webpack context.
Run 'npm install --save-dev html-webpack-plugin' or 'yarn add --dev html-webpack-plugin'.
Use default import: 'import HtmlWebpackPlugin from 'html-webpack-plugin'' or 'const HtmlWebpackPlugin = require('html-webpack-plugin')'.