-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache breaks asset module live reloading #13275
Comments
Do you have |
Might be fixed by #13276 |
Yes, I'm using |
This should be fixed in the latest version |
Confirmed, fixed by https://github.com/webpack/webpack/releases/tag/v5.36.2, the same issue webpack/webpack-dev-server#3175 (comment), let's close, feel free to feedback |
It seems that bug still exists. I'm using webpack 5.57.1 and with output.clean = true image assets not fount after hot reload. |
Please provide reproducible test repo |
|
@jantimon This is related to the caching in html-webpack-plugin. |
Duplicate jantimon/html-webpack-plugin#1639 |
@alexilin83 Workaround - |
Doesn't work for me. I updated the test repository. |
hm, weird, looks like it is not real disable cache, anyway we can't fix it here |
ok, thanks anyway. |
that would be a regression - html-webpack-plugin writes asset for every compilation and |
@jantimon here repo https://github.com/alexilin83/webpack_test_image, check this |
No problems without |
@jantimon the main problem - |
@jantimon You should emit child assets, go to here https://github.com/jantimon/html-webpack-plugin/blob/main/lib/child-compiler.js#L151, write |
To fix this: in result[this.templates[entryIndex]] = {
content: templateSource,
hash: childCompilation.hash || 'XXXX',
entry: entries[entryIndex],
assets: childCompilation.assets,
};
if (isCompilationCached && options.cache && assetJson === newAssetJson) {
previousEmittedAssets.forEach(({ name, html, source }) => {
compilation.emitAsset(name, source ? source : new webpack.sources.RawSource(html, false));
});
return callback();
} else {
previousEmittedAssets = [];
assetJson = newAssetJson;
}
// ...
// ...
// ...
const replacedFilename = replacePlaceholdersInFilename(filename, html, compilation);
// Add the evaluated html code to the webpack assets
compilation.emitAsset(replacedFilename.path, new webpack.sources.RawSource(html, false), replacedFilename.info);
previousEmittedAssets.push({ name: replacedFilename.path, html });
Object.keys(templateResult.compiledEntry.assets).forEach((name) => {
const source = templateResult.compiledEntry.assets[name];
previousEmittedAssets.push({ name: name, source });
})
return replacedFilename.path; Note - it is simple fix and not full, you should keep A while ago I asked you to move repo inside |
thanks alex - sorry I had a long work day yesterday.. let me take a look :) to summarise the issue to ensure we are on the same page:
Can we move this bug to the html-webpack-plugin issue tracker? Maybe a short note on
Caching is a tricky topic and 7 years ago when the html-webpack-plugin was created it was very difficult to have a good performance for child compiler especially without an entry point in webpack I am happy for better caching ideas - or even better remove them if they are no longer needed.. new HtmlWebpackPlugin({
templateContent: ({htmlWebpackPlugin}) => `
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
`
}) one challenge for caching was that some people use the HtmlWebpackPlugin to generate many many many files out of the same template e.g.: new HtmlWebpackPlugin({
filename: "[name].html"
}) Do you think we could solve all those cases with an additional |
@jantimon Only you can move this issue to |
Fixed in html-webpack-plugin |
Bug report
What is the current behavior?
Live reloading breaks for assets using
asset/resource
rule type when caching is enabled.If the current behavior is a bug, please provide the steps to reproduce.
Add an asset loader rule:
Import an asset
The initial page load works as expected.
Commenting out the
img
and/or import, then reverting causes the image asset to be not found.Disabling the cache "fixes" the issue
It's also not an issue when using
asset/inline
.webpack.config.js
What is the expected behavior?
I know "it should work" is not helpful, but it seems self explanatory here.
Other relevant information:
webpack version: 5.36.1
Node.js version: 10.24.1
Operating System: OS X 10.14.6
Additional tools:
The text was updated successfully, but these errors were encountered: