Skip to content

Commit e666a8e

Browse files
authored
feat: Add excludeReplayWorker to bundleSizeOptimizations (#433)
1 parent ddd1322 commit e666a8e

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ export function sentryUnpluginFactory({
183183
if (bundleSizeOptimizations.excludeReplayShadowDom) {
184184
replacementValues["__RRWEB_EXCLUDE_SHADOW_DOM__"] = true;
185185
}
186+
if (bundleSizeOptimizations.excludeReplayWorker) {
187+
replacementValues["__SENTRY_EXCLUDE_REPLAY_WORKER__"] = true;
188+
}
186189

187190
if (Object.keys(replacementValues).length > 0) {
188191
plugins.push(bundleSizeOptimizationsPlugin(replacementValues));

packages/bundler-plugin-core/src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ export interface Options {
267267
* Note that the success of this depends on tree shaking generally being enabled in your build.
268268
*/
269269
excludeReplayIframe?: boolean;
270+
271+
/**
272+
* If set to true, the plugin will try to tree-shake Session Replay's Compression Web Worker out.
273+
* You should only do this if you manually host a compression worker and configure it in your Replay config via `workerUrl`.
274+
* Note that the success of this depends on tree shaking generally being enabled in your build.
275+
*/
276+
excludeReplayWorker?: boolean;
270277
};
271278

272279
/**
@@ -395,6 +402,7 @@ export interface SentrySDKBuildFlags extends Record<string, boolean | undefined>
395402
__RRWEB_EXCLUDE_CANVAS__?: boolean;
396403
__RRWEB_EXCLUDE_IFRAME__?: boolean;
397404
__RRWEB_EXCLUDE_SHADOW_DOM__?: boolean;
405+
__SENTRY_EXCLUDE_REPLAY_WORKER__?: boolean;
398406
}
399407

400408
type SetCommitsOptions = (AutoSetCommitsOptions | ManualSetCommitsOptions) & {

packages/integration-tests/fixtures/bundle-size-optimizations/bundle-size-optimizations.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";
77
const expectedOutputs: Record<string, Record<string, string>> = {
88
esbuild: {
99
"bundle1.js": `console.log(1)`,
10-
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"})`,
10+
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`,
1111
},
1212
rollup: {
1313
"bundle1.js": `console.log(1 );`,
@@ -17,19 +17,20 @@ const expectedOutputs: Record<string, Record<string, string>> = {
1717
replayCanvas: "a" ,
1818
replayIframe: "a" ,
1919
replayShadowDom: "a" ,
20+
replayWorker: "a" ,
2021
});`,
2122
},
2223
vite: {
2324
"bundle1.js": `console.log(1);`,
24-
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"});`,
25+
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`,
2526
},
2627
webpack4: {
2728
"bundle1.js": `console.log(1)`,
28-
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"})`,
29+
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`,
2930
},
3031
webpack5: {
3132
"bundle1.js": `console.log(1)`,
32-
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a"});`,
33+
"bundle2.js": `console.log({debug:"b",trace:"b",replayCanvas:"a",replayIframe:"a",replayShadowDom:"a",replayWorker:"a"})`,
3334
},
3435
};
3536

packages/integration-tests/fixtures/bundle-size-optimizations/input/bundle2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ console.log({
44
replayCanvas: __RRWEB_EXCLUDE_CANVAS__ ? "a" : "b",
55
replayIframe: __RRWEB_EXCLUDE_IFRAME__ ? "a" : "b",
66
replayShadowDom: __RRWEB_EXCLUDE_SHADOW_DOM__ ? "a" : "b",
7+
replayWorker: __SENTRY_EXCLUDE_REPLAY_WORKER__ ? "a" : "b",
78
});

packages/integration-tests/fixtures/bundle-size-optimizations/setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ createCjsBundles(
2020
excludeReplayCanvas: true,
2121
excludeReplayIframe: true,
2222
excludeReplayShadowDom: true,
23+
excludeReplayWorker: true,
2324
},
2425
}
2526
);

0 commit comments

Comments
 (0)