question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Template is emitted even if unchanged and `cache: true`.

See original GitHub issue

Current 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jantimoncommented, Apr 28, 2021

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 cache option was added to allow opting out

Back 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

0reactions
stale[bot]commented, Apr 16, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading and writing data to the cache - Apollo GraphQL Docs
In the example above, every cached Todo object has its completed field set to true (and other fields remain unchanged). If the update...
Read more >
Client-Side Caching of Apex Method Results
To set cacheable=true , a method must only get data, it can't mutate (change) data. Marking a method as cacheable improves your component's...
Read more >
How to force browsers to reload cached CSS and JS files?
The mod_rewrite method works well if you want to force a reload of the .css or .js file EVERY time you load the...
Read more >
Cache - webpack
Collect unused memory allocated during deserialization, only available when cache.type is set to 'filesystem' . This requires copying data into smaller ...
Read more >
Caching in GitLab CI/CD
For examples, see the GitLab CI/CD templates. ... Even if the key is different, the cached files might get “cleaned” before each stage...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found