soundcloud / chunk-manifest-webpack-plugin

Allows exporting a manifest that maps entry chunk names to their output files, instead of keeping the mapping inside the webpack bootstrap.
MIT License
395 stars 73 forks source link

Chunkhash in filename still differs #7

Open alexhancock opened 9 years ago

alexhancock commented 9 years ago

This plugin works great, thanks for writing it.

I'm experiencing an issue where the contents of a commons chunk are now identical across compiles where the only code changed is not in the commons chunk, but the chunkHash webpack outputs for the commons chunk filename is still different.

Anyone else ever run into this?

alexhancock commented 9 years ago

(This may totally be an issue in webpack itself, I just thought I would post an issue here as the likelihood someone looking at this repo has run into this problem is higher than webpack repo itself)

kevinrenskers commented 9 years ago

I just created this issue: https://github.com/webpack/webpack/issues/1315. Has an example as well: https://github.com/kevinrenskers/chunkhash-problem.

alexhancock commented 9 years ago

Cool - glad to see I'm not alone.

I'll follow that thread and this one to see if anyone has relevant knowledge towards cause or a fix.

bholloway commented 8 years ago

+1

bholloway commented 8 years ago

Is this still a pain point for others?

I found a solution that works for my use-case. I will raise a PR so @diurnalist and others can critique. But tomorrow after sleep.

bholloway commented 8 years ago

So at startup WebpackOptionsApply adds a lot of default plugins. One of them is TemplatedPathPlugin, at WebpackOptionsApply.js#L266.

Noting that MainTemplate is the implementation of compilation.mainTemplate the MainTemplate.updateHashForChunk() routine will determine the hash of the entry chunk. It exposes a "hash-for-chunk" extensibility point which is hooked by TemplatedPathPlugin.

The problem is that TemplatedPathPlugin adds the hashes of other chunks into the digest. I believe this is on the presumption that the entry chunk will contain the chunk manifest. The hashing routine is not a pure function so simply adding another "hash-for-chunk" routine will not undo the effects of TemplatedPathPlugin.

I am proposing a monkey-patch of MainTemplate.updateHashForChunk() such that it does not call the "hash-for-chunk" extensibility point. This is working for my use-case (sorry closed source). I am interested whether this solves the problem for @alexhancock and @kevinrenskers.

You can install from bholloway/chunk-manifest-webpack-plugin and I have PR #9.

Additionally, let me know if this is relevant to webpack/webpack#1315.

bholloway commented 8 years ago

This issue should be closed based on the response to the question I posed.

Essentially if you use webpack-md5-hash plugin the problem goes away.

Refer to webpack/webpack#1315 for a full solution.

gingur commented 8 years ago

Using the md5hash plugin still having an issue with naming of the chunks; PR https://github.com/diurnalist/chunk-manifest-webpack-plugin/pull/11

gingur commented 8 years ago

knock knock