-
Notifications
You must be signed in to change notification settings - Fork 10
Extract installed chunks mapping's variable for improved long-term caching #14
Comments
@huangshuwei do you have some examples? when i use, it throw error |
@lomotony |
try more detail: Predictable long term caching with Webpack |
As of closing PR #18 this can now be worked on. I'd much appreciate a PR. Currently, I don't really have the time to solving this one. 👶 👶 require a lot of 😍 . |
Yes this is bugging us too, webpack generates the hashes of files before starting the compilation. This means our final webpack runtime chunk is byte for byte equal to a version with a different chunkhash because the file at the start used to be different (it was hashed with the manifest still in there). @jouni-kantola |
Accidentally closed when typing 😁 What I was going to write was:
|
Related by outcome for sure ^_^ After tuning and reading the webpack source I have something that also works if the runtime code is inside another chunk! plugins: [
{
apply(compiler) {
compiler.plugin("this-compilation", compilation => {
const { hashFunction, hashDigest, hashDigestLength, hashSalt } = compilation.outputOptions;
compilation.mainTemplate.plugin("require-ensure", (source, chunk) => {
const chunkHash = crypto.createHash(hashFunction);
if (hashSalt)
chunkHash.update(hashSalt);
chunk.updateHash(chunkHash);
chunk.hash = chunkHash.digest(hashDigest);
chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
})
});
}
}
] Basically the new content for the chunkHash is added by the chunk itself and we only do this to the runtime chunk, the hashoptions set by the user in This keeps the runtime chunk stable by re-examining what the actual content that would be written to disk would be, and as there is nothing identifiable/volatile in there it stays constant. The hash will update when:
As we don't have to recursively change hashes because everything stays stable or is externalized into the manifest just updating this single chunk's hash is enough. See link for related code in webpack |
@NinoFloris:
which to me reads that your runtime asset has same content after extracting the chunk manifest, but changes hash anyways. If I understood you correctly, then please create a new issue for this. |
Yes which is variable due to not using named chunks, as the only initial entry will ever be the runtime chunk, once you do that you get the next issue which is what I've posted here. all roads lead to this problem |
I agree your issue should be fixed, @NinoFloris, and I'd happily take a PR, but it's not the same problem as the issue here (I'll rename this issue). The manifest asset could be made even stickier. You can repro by e.g. trying updating a static import to a dynamic import. I've created a new issue where we can continue this discussion: #22 |
Thanks for creating the other issue :) Although I have to add, as I said, the { #runtimechunkid#: 0 } In the normal case this is a number and it can/will change based on how many chunks you have, whereas in my case its says "runtime" because we use named chunks and it's therefore stable. This means as long as the runtime chunk code doesn't change, I'll have exactly the same output every build. If @huangshuwei would add new webpack.NamedModulesPlugin(), //optional-ish
new webpack.NamedChunksPlugin(), To his plugins like @ufologist linked to, then he'll be in the same boat as where I was
|
@NinoFloris: Thank you for your perseverance 🥇 But still, I'm not sure |
Basically that happens here https://github.com/webpack/webpack/blob/8b0a2ad2b3298372bf09ec22017e373625f5b06a/lib/JsonpMainTemplatePlugin.js#L12 I'm not sure though if you can just remove that entry, something has to bootstrap the bootstrapper basically in this case, that's why the initial entry is the runtime chunk. |
Hi:
Even if the hash of assets information is extracted from the manifest.js file by html inline. but manifest.js file changes when assets change every time.
this part of the manifest.js file changes every time:
Unless this part is also extracted from the manifest.js file, cache problem will be solved.
The text was updated successfully, but these errors were encountered: