jantimon / jantimon/html-webpack-plugin

Dev server is not rebuilding the HTML file when using templating

Open
#1,745 1 comment 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
JavaScript
Stars
10.7k
Forks
1.3k
Avg merge
1m
Merged PRs (30d)
1

Description

## 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
```ts
new HtmlWebpackPlugin({
filename: "./index.html",
template: resolve(__dirname, "../static/index.html"),
inject: "body",
}),
```
- Insert the template
```html

<%= compilation.assets["html/head.html"].source() %>


```
- Save the `head.html` file.
- The fill will not be rebuilt (sometimes it rebuilds for me but only once)
- My full source code is available here https://github.com/Miodec/monkeytype

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 🖥

```
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

monkeytype@1.5.6 /Users/jackbartnik/Documents/Code/monkeytype
└── (empty)

npm ls html-webpack-plugin

monkeytype@1.5.6 /Users/jackbartnik/Documents/Code/monkeytype
└── (empty)

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the HtmlWebpackPlugin configuration, index.html, and the referenced head.html template from the linked example. Start by checking how saving head.html affects the webpack dev-server rebuild, then verify that saving a template consistently rebuilds index.html using the updated template.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, webpack
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.