sentry-javascript-bundler-plugins icon indicating copy to clipboard operation
sentry-javascript-bundler-plugins copied to clipboard

Add support for Rolldown/Vite hook filters

Open s1gr1d opened this issue 8 months ago • 3 comments

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+.

Docs: Rolldown Docs: Vite

s1gr1d avatar Jun 24 '25 12:06 s1gr1d

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

s1gr1d avatar Jun 24 '25 13:06 s1gr1d

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!

timfish avatar Jul 15 '25 19:07 timfish

We need to upgrade to version 2.3.0 of 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

s1gr1d avatar Jul 16 '25 11:07 s1gr1d