Add support for Rolldown/Vite hook filters
This came up on X where someone compared the load times: https://x.com/TheAlexLichter/status/1930977073931206928
The problem hook filters solve is getting rid of the JS-to-Rust overhead by only invoking a plugin call when it's necessary. For example in this case, we can add a hook filter, that only considers files which include .data:
transform(code, id) {
if (!id.endsWith('.data')) { }
}
With a filter, this looks like this:
transform: {
filter: {
id: /\.data$/
},
handler (code) { /* the actual transform handler code */ }
The feature is also supported by Rollup 4.38.0+ and Vite 6.3.0+.
We need to upgrade to version 2.3.0 of unplugin to have support for filters which were added in this PR: https://github.com/unjs/unplugin/pull/494
At this point I'm not convinced unplugin is actually helping us much. We already use bundler specific hooks that unplugin doesn't support.
By far the "best" hook we can use to inject code with Rollup | Rolldown | Vite is renderChunk because it gets called for every output chunk rather than every module (file). ie. it'll get called A LOT less so it'll have less performance impact.
We already use renderChunk for debugID injection and some other things but not for release injection. If we migrate everything over to `renderChunk we'll improve perf. but then we might as well not be using unplugin for those bundlers!
We need to upgrade to version
2.3.0of unplugin
We don't need to upgrade the version as the hook filters a backwards-compatible in Vite/Rolldown, but the newer unplugin version would add support for the correct types. Currently, we wouldn't have proper type support.
Cross-Referencing this comment about moving away from unplugin: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/359#issuecomment-1658606815