Fix sourcemap in projects with code splitting#113
Conversation
|
Hi, thanks for the PR and the analysis. The build is failing, can you see why? I will also try and have a look. It would be good to have a test case to demonstrate the need for this change, ie. one that fails before changing the hooks and succeeds after. This would ensure that source maps continue to be accurate in the future. Relying on the order in which hooks are invoked can be fragile. Perhaps an alternate solution to this problem would be to ensure that placeholders have the same length as the replacement text. We could exploit the fact that all common hash functions produce a fixed-length result. |
|
Thanks for the comments @jscheid ! Yeah, I agree that changing the placeholder may be a better idea. - I just generate a dummy sha in this case. Updated PR and added a test example. Please let me know what you think about it. |
|
friendly ping @jscheid . Do you have time to take another look? Thanks! |
jscheid
left a comment
There was a problem hiding this comment.
Good catch and great fix, thank you!
Thanks for your patience as well, the last few weeks have been quite busy for me.
I'm going to try and cut a release from this very soon, but there are a few other little things that have to go in. I'll comment on the PR when it's out, shouldn't be long.
|
@baileyid this is released in v1.3.3. |
|
awesome. thank you! |
We’ve noticed an issue when using this plugin in projects with code splitting. Basically there are placeholders of SRI hashes being added to js binary, which are later replaced with real hash values. However, the placeholders in sourcemap files are not updated, so there could be a mismatch between the source code and sourcemap after where the variable of

sriHashesis injected.The cause is probably because the function of
processChunk(which callsreplaceAsset) is tapped toafterOptimizeAssetshook, while in webpack, the plugin that actually generates sourcemap is tapped toafterOptimizeChunkAssetshook. Probably in projects that don’t use code splitting, the two hooks happen at the same time, but in projects with code splitting,afterOptimizeChunkAssetshappens beforeafterOptimizeAssets, sosriHashesreplacement could break the sourcemap which was generated before that.Changing the hook looks like fixing the issue.
