Rowan Freeman's 2020 answer doesn't work for me; it's December 2024 right now, and I'm using the current html-webpack-plugin 5.6.0 on RsPack (which supports almost all of the api of webpack5, so I think this answer applies to webpack5 as well). I'm also using an RsPack .mjs script to invoke the RsPack JS api, not a .js, so I needed to use mHtmlWebpackPlugin = await import("html-webpack-plugin")
instead of require
.
What does work is to invoke the plugin with .default
like this:
plugins: [
new mHtmlWebpackPlugin.default({
template: "template.html"
})
]
I discovered this in the following way:
debugger;
Note that you don't have to name the import mHtmlWebpackPlugin
; you can strip the leading m
or name it whatever you want.
Btw, static import import * as mHtmlWebpackPlugin from "html-webpack-plugin";
also works.