Template is emitted even if unchanged and `cache: true`.
See original GitHub issueCurrent behaviour 💣
The docs state that with cache: true, the plugin will “emit the file only if it was changed”. However, even if the template is cached and entirely unchanged, it is emitted (even if not recompiled) on every Webpack build.
assets by status 16.9 MiB [cached] 30 assets
asset templates/index.html 2.31 KiB [emitted]
Expected behaviour ☀️
I would expect that if cache: true is set and a rebuild is triggered with no changes to the template, it would not be re-emitted:
assets by status 16.9 MiB [cached] 30 assets
My use-case is that the generated template is being served by a Django server, which auto-reloads every time it is built (even if unchanged).
Reproduction Example 👾
https://github.com/jantimon/html-webpack-plugin/compare/main...jgerigmeyer:no-emit-cached-asset
It appears that even when a file is cached and unchanged, it is still re-emitted. The tests for caching only seem to assert that it is not recompiled. Is this intentional? Apologies if I’m misunderstanding a reason why cached files need to be re-emitted when unchanged. (If so, perhaps I could submit a PR to update the docs to make this more clear?)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)

Top Related StackOverflow Question
The main idea of the cache is to save time by avoiding unnecessary recompilations
Unfortunately there are some edge cases which requires to recompile on every webpack run
So the
cacheoption was added to allow opting outBack then html files were only emitted if the content changes - however with a recent version of webpack it was necessary to emit the file every time to keep compatibility with clean-webpack-plugin and the copy plugin
This issue had no activity for at least half a year. It’s subject to automatic issue closing if there is no activity in the next 15 days.