diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index 3dc36c0d..d7f46758 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -183,6 +183,9 @@ export function sentryUnpluginFactory({ if (bundleSizeOptimizations.excludeReplayShadowDom) { replacementValues["__RRWEB_EXCLUDE_SHADOW_DOM__"] = true; } + if (bundleSizeOptimizations.excludeReplayWorker) { + replacementValues["__SENTRY_EXCLUDE_REPLAY_WORKER__"] = true; + } if (Object.keys(replacementValues).length > 0) { plugins.push(bundleSizeOptimizationsPlugin(replacementValues)); diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index 15a9ca1d..08325777 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -267,6 +267,13 @@ export interface Options { * Note that the success of this depends on tree shaking generally being enabled in your build. */ excludeReplayIframe?: boolean; + + /** + * If set to true, the plugin will try to tree-shake Session Replay's Compression Web Worker out. + * You should only do this if you manually host a compression worker and configure it in your Replay config via `workerUrl`. + * Note that the success of this depends on tree shaking generally being enabled in your build. + */ + excludeReplayWorker?: boolean; }; /** @@ -395,6 +402,7 @@ export interface SentrySDKBuildFlags extends Record __RRWEB_EXCLUDE_CANVAS__?: boolean; __RRWEB_EXCLUDE_IFRAME__?: boolean; __RRWEB_EXCLUDE_SHADOW_DOM__?: boolean; + __SENTRY_EXCLUDE_REPLAY_WORKER__?: boolean; } type SetCommitsOptions = (AutoSetCommitsOptions | ManualSetCommitsOptions) & { diff --git a/packages/integration-tests/fixtures/bundle-size-optimizations/bundle-size-optimizations.test.ts b/packages/integration-tests/fixtures/bundle-size-optimizations/bundle-size-optimizations.test.ts index a12d9f78..fb754943 100644 --- a/packages/integration-tests/fixtures/bundle-size-optimizations/bundle-size-optimizations.test.ts +++ b/packages/integration-tests/fixtures/bundle-size-optimizations/bundle-size-optimizations.test.ts @@ -7,7 +7,7 @@ import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; const expectedOutputs: Record> = { esbuild: { "bundle1.js": `console.log(1)`, - "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"})`, + "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`, }, rollup: { "bundle1.js": `console.log(1 );`, @@ -17,19 +17,20 @@ const expectedOutputs: Record> = { replayCanvas: "a" , replayIframe: "a" , replayShadowDom: "a" , + replayWorker: "a" , });`, }, vite: { "bundle1.js": `console.log(1);`, - "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"});`, + "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`, }, webpack4: { "bundle1.js": `console.log(1)`, - "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"})`, + "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`, }, webpack5: { "bundle1.js": `console.log(1)`, - "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"});`, + "bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`, }, }; diff --git a/packages/integration-tests/fixtures/bundle-size-optimizations/input/bundle2.js b/packages/integration-tests/fixtures/bundle-size-optimizations/input/bundle2.js index 436e11bc..e6c49f94 100644 --- a/packages/integration-tests/fixtures/bundle-size-optimizations/input/bundle2.js +++ b/packages/integration-tests/fixtures/bundle-size-optimizations/input/bundle2.js @@ -4,4 +4,5 @@ console.log({ replayCanvas: __RRWEB_EXCLUDE_CANVAS__ ? "a" : "b", replayIframe: __RRWEB_EXCLUDE_IFRAME__ ? "a" : "b", replayShadowDom: __RRWEB_EXCLUDE_SHADOW_DOM__ ? "a" : "b", + replayWorker: __SENTRY_EXCLUDE_REPLAY_WORKER__ ? "a" : "b", }); diff --git a/packages/integration-tests/fixtures/bundle-size-optimizations/setup.ts b/packages/integration-tests/fixtures/bundle-size-optimizations/setup.ts index 74699d2a..8e1fb1dc 100644 --- a/packages/integration-tests/fixtures/bundle-size-optimizations/setup.ts +++ b/packages/integration-tests/fixtures/bundle-size-optimizations/setup.ts @@ -20,6 +20,7 @@ createCjsBundles( excludeReplayCanvas: true, excludeReplayIframe: true, excludeReplayShadowDom: true, + excludeReplayWorker: true, }, } );