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
chunk hash is changed by manualChunks even if not modify any module #4394
Comments
@CaptainLiao which version of |
@dnalborczyk my rollup version is 2.61.1. sorry for my careless. later I update rollup v2.67.1, but get same result——chunks's hash also be changed. first build:
second build:
Everything are same , just run build command twice. as you see, chunks's hash has be changed except third packages. |
I think I understand the issue. When using a manual chunks function, the order in which the chunks is generated is arbitrary. While this should not influence hashes too much, it can actually have an effect because the chunk order can also influence other things (the current algorithm is far from perfect). I would propose a slightly different fix, explicitly sort just the aliased modules (and not all modules, which can be quite a lot) by alias: private assignManualChunks(getManualChunk: GetManualChunk): Map<Module, string> {
const manualChunkAliasesWithEntry: [alias: string, module: Module][] = [];
const manualChunksApi = {
getModuleIds: () => this.graph.modulesById.keys(),
getModuleInfo: this.graph.getModuleInfo
};
for (const module of this.graph.modulesById.values()) {
if (module instanceof Module) {
const manualChunkAlias = getManualChunk(module.id, manualChunksApi);
if (typeof manualChunkAlias === 'string') {
manualChunkAliasesWithEntry.push([manualChunkAlias, module]);
}
}
}
manualChunkAliasesWithEntry.sort(([aliasA], [aliasB]) =>
aliasA > aliasB ? 1 : aliasA < aliasB ? -1 : 0
);
const manualChunkAliasByEntry = new Map<Module, string>();
for (const [alias, module] of manualChunkAliasesWithEntry) {
addModuleToManualChunk(alias, module, manualChunkAliasByEntry);
}
return manualChunkAliasByEntry;
} Can you try out if this would also solve your issue? |
PR here: #4397 |
bravo! I use your code that could fixed the issue. waiting for your merge. again, thx. |
I have a similar but somwhat different problem。 |
rollup: v14.16.1
platform: window10
node: v14.16.1
I use rollup to build my webapp,and create many named chunks by manualChunks.
question is: every time i run rollup build command, all chunks's hash would be changed, even if not modify any module/content, just rerun build command!
I find the source code:
and make some change (just sort this.graph.modulesById.values() by module id):
everything is ok. the change is right?
I guess
this.graph.modulesById.values()
has not fixed sequence, so same chunk have different module sequence in every build, right?I find there has orderedModule, but this.graph.modulesById.values() is not sorted, this can be fixed? thx.
The text was updated successfully, but these errors were encountered: