Skip to content

Commit

Permalink
feat: Add excludeReplayWorker to bundleSizeOptimizations (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea authored Oct 31, 2023
1 parent ddd1322 commit e666a8e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 8 additions & 0 deletions packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -395,6 +402,7 @@ export interface SentrySDKBuildFlags extends Record<string, boolean | undefined>
__RRWEB_EXCLUDE_CANVAS__?: boolean;
__RRWEB_EXCLUDE_IFRAME__?: boolean;
__RRWEB_EXCLUDE_SHADOW_DOM__?: boolean;
__SENTRY_EXCLUDE_REPLAY_WORKER__?: boolean;
}

type SetCommitsOptions = (AutoSetCommitsOptions | ManualSetCommitsOptions) & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";
const expectedOutputs: Record<string, Record<string, string>> = {
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 );`,
Expand All @@ -17,19 +17,20 @@ const expectedOutputs: Record<string, Record<string, string>> = {
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"})`,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ createCjsBundles(
excludeReplayCanvas: true,
excludeReplayIframe: true,
excludeReplayShadowDom: true,
excludeReplayWorker: true,
},
}
);

0 comments on commit e666a8e

Please sign in to comment.