79299269

Date: 2024-12-21 10:52:57
Score: 1.5
Natty:
Report link

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:

  1. Add only the import you want to try, not any invocation
  2. Place a breakpoint just after the import, such as by inserting debugger;
  3. Run the build script in debug mode (I used VSCode) and when the breakpoint is reached, examine the structure of what was imported.

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.

Reasons:
  • Blacklisted phrase (0.5): I need
  • RegEx Blacklisted phrase (2): doesn't work for me
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: DavidP