-
Notifications
You must be signed in to change notification settings - Fork 45
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
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
![image](https://user-images.githubusercontent.com/8864469/62658909-c6625000-b91e-11e9-8d52-acf45a406ca6.png)
sriHashes
is injected.The cause is probably because the function of
processChunk
(which callsreplaceAsset
) is tapped toafterOptimizeAssets
hook, while in webpack, the plugin that actually generates sourcemap is tapped toafterOptimizeChunkAssets
hook. Probably in projects that don’t use code splitting, the two hooks happen at the same time, but in projects with code splitting,afterOptimizeChunkAssets
happens beforeafterOptimizeAssets
, sosriHashes
replacement could break the sourcemap which was generated before that.Changing the hook looks like fixing the issue.
![image](https://user-images.githubusercontent.com/8864469/62659182-8485d980-b91f-11e9-94aa-ace8fde84af9.png)