The `html-bundler-webpack-plugin` is a Webpack plugin designed to streamline the creation of single-page or multi-page websites directly from HTML templates. Unlike `html-webpack-plugin` which primarily injects bundled assets, this plugin treats HTML files as entry points, resolving all linked assets (scripts, styles, images, fonts) within the HTML and CSS itself. It handles asset processing and ensures correct output URLs after Webpack's build. Key differentiators include built-in support for numerous template engines like Eta, EJS, Handlebars, Nunjucks, Pug, Tempura, TwigJS, LiquidJS, and Markdown out-of-the-box. It also simplifies asset resolution in CSS without requiring `resolve-url-loader`. The plugin is currently in a very active development state, with version 4.23.0 being the latest stable release, and frequent updates addressing features, fixes, and Webpack compatibility.
npm install html-bundler-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
This quickstart sets up a basic Webpack configuration to compile two HTML entry points (`index.html`, `about.html`), processing linked SCSS, JavaScript, and SVG/image assets. It demonstrates aliased paths and hashed output filenames.
Ensure your Node.js version is >=18 and Webpack is >=5.81. If extending the plugin, update references from `MyPlugin.option` to `this.option` within the plugin instance methods.
Upgrade `html-bundler-webpack-plugin` to version 4.2.0 or higher if you are using Webpack 5.96.0 or newer.
To revert to the old behavior (replacing `<img>` with `<svg>` tag), set the `svg.inline.embed` option to `true` in the plugin configuration. For explicit base64 encoding or escaped URLs, use query parameters like `?inline=base64` or `?inline=escape`.
Review and update any custom `PreloadFilter` functions to align with the new type definition which now expects a function that returns `void | boolean` and receives an `asset` object with `sourceFiles` and `outputFile` properties.
If encountering CSS resolution issues with `splitChunks`, review your Webpack `optimization.splitChunks` configuration. Consider adjusting `css.inline` or `css.filename` options, or temporarily disabling `splitChunks` for CSS to diagnose.
Refactor your Webpack configuration to leverage the built-in asset resolution and template engine support. Remove redundant loaders for HTML processing, CSS URL resolution (like `resolve-url-loader`), and script/style injection plugins.
Carefully inspect the specified HTML template file at the given position. While the error mentions a missing `>`, it can also indicate other parsing issues. Ensure all tags are properly nested and self-closing tags are correctly formatted. Sometimes, simplifying complex HTML structures or ensuring valid HTML5 can resolve this.
Ensure you are using `import { HtmlBundlerPlugin } from 'html-bundler-webpack-plugin';` in an ESM-enabled Webpack configuration file (e.g., `webpack.config.mjs` or `webpack.config.js` with `type: module` in `package.json`). If you must use CommonJS, ensure your environment correctly transpiles ESM or the package provides a CJS entry point.Although this specific error message refers to `html-webpack-plugin`, the underlying cause (incompatible plugin hooks) can apply to any Webpack plugin. Ensure all Webpack-related packages, including `html-bundler-webpack-plugin` and any plugins that extend it, are compatible with your Webpack version. Update to the latest versions if possible.
Verify the path to 'file.css' is correct relative to the HTML template or resolve `alias` configuration. Check your `module.rules` in `webpack.config.js` to ensure that CSS files are being correctly handled (e.g., `css-loader`, `sass-loader`) and that the output filename configuration for CSS (`css.filename`) is correctly set.