Skip to content

feat: Add excludeReplayWorker to bundleSizeOptimizations #433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
}
);