-
Notifications
You must be signed in to change notification settings - Fork 45
fix: Use renderChunk
for release injection for Rollup/Rolldown/Vite
#761
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: Use renderChunk
for release injection for Rollup/Rolldown/Vite
#761
Conversation
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.
Do we have an idea of how much this saves build times?
Hard to guess really but if this was the only usage of the However, because we will still be left with other usages of For example if If we can do something like this and use filters to only target specific files we should see a bigger impact. Rolldown also has it own native React component annotations require |
One thing I realized: #610 (comment) so if we move to renderChunk, the injection code basically need to be es5(?) compatible? We're talking about this right now in #769 and internally on Slack. According to #770, the required code changes wouldn't be too bad 🤔 |
I don't really know how polyfilling tools work with bundlers but it's easier to just make the injected code ES5 compatible! |
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.
Thanks Tim! Let's merge this after #770 to ensure we don't break anyone accidentally.
As a follow-up, we should also "minify" the release and moduleMetaData injection snippets, given that renderChunk
likely happens after minification (At least I think so, since our debugId snippet is already minified). Can you take care of that?
Yeah good point, I'll take care of that. Out of curiosity I'm going to check the minification plugins to see what hooks they use anyway. Do we enforce/suggest some plugin order when using our bundler plugins? |
I don't think we enforce any ordering, we rely on the individual bundler hooks themselves to run things at the correct time. |
In some rare cases, we need a specific order (e.g. sveltekit). Other than that, some of our plugins using the |
Rollup terser plugin uses |
I minified the release info injected code and also did the same for module metadata injection since the same issues exist there. We could save a small amount of bundle size by combining these plugins. I moved away from inline snapshots for these tests because with all the code all on a single line it becomes unwieldy! |
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.
Thanks for doing the minification right away! I think in this case, it's better to be safe than sorry, and avoid depending on plugin order as much as possible.
Also given that we have integration tests that actually test the behaviour of the (now minified) snippets I think this is safe to merge.
To inject release info code via the unplugin hooks we were using
resolveId
/load
/transform
but this is not ideal because these hooks get called for every module (ie. every input file!).We only need to do this injection per bundle output file. We already use Rollups specific
renderChunk
hook for injecting code which allows us to inject code only into the final chunks.This PR migrates release injection to use the same
renderChunk
hook which is already used for metadata injection.