Dev server is not rebuilding the HTML file when using templating

Author: MiodecCreated Apr 20, 2022Updated Jan 2, 2026
Labelswontfix

Current behaviour

Im using HTML templating to reduce the size of my HTML file. If I save index.html, the webpack dev server correctly rebuilds the file. However, if I save one of the template files, this does not happen.

Expected behaviour ☀️

The HTML file should be rebuilt using the templates if a template file is saved.

Reproduction Example

  • Initialise the HtmlWebpackPlugin
typescript
new HtmlWebpackPlugin({
      filename: "./index.html",
      template: resolve(__dirname, "../static/index.html"),
      inject: "body",
    }),
  • Insert the template
xml
<!DOCTYPE html>
<html lang="en">
  <%= compilation.assets["html/head.html"].source() %>

  <body>

I also tried setting it up on codesandbox but couldn't get the other HTML file to show up in compilation.assets https://codesandbox.io/s/html-webpack-plugin-5-x-alpha-forked-772ck7?file=/src/index.html

Hopefully this is okay, if not let me know.

Environment

bash
node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"

Node.js v16.13.2
darwin 21.4.0

npm --version

8.1.2

npm ls webpack

[email protected] /Users/jackbartnik/Documents/Code/monkeytype
└── (empty)

npm ls html-webpack-plugin

[email protected] /Users/jackbartnik/Documents/Code/monkeytype
└── (empty)

Source: jantimon/html-webpack-plugin