Skip to content

Commit 4fa73fd

Browse files
committed
feat(nextjs): Add bundleSizeOptimizations to build options
1 parent 2c24a33 commit 4fa73fd

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

packages/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"@sentry/types": "8.25.0",
7979
"@sentry/utils": "8.25.0",
8080
"@sentry/vercel-edge": "8.25.0",
81-
"@sentry/webpack-plugin": "2.20.1",
81+
"@sentry/webpack-plugin": "2.22.0",
8282
"chalk": "3.0.0",
8383
"resolve": "1.22.8",
8484
"rollup": "3.29.4",

packages/nextjs/src/config/types.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,53 @@ export type SentryBuildOptions = {
307307
};
308308
};
309309

310+
/**
311+
* Options for the Sentry Webpack plugin to customize bundle size optimizations.
312+
*
313+
* These options are always read from the `sentryAstro` integration.
314+
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
315+
*/
316+
bundleSizeOptimizations?: {
317+
/**
318+
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK.
319+
* Note that the success of this depends on tree shaking being enabled in your build tooling.
320+
*
321+
* Setting this option to `true` will disable features like the SDK's `debug` option.
322+
*/
323+
excludeDebugStatements?: boolean;
324+
325+
/**
326+
* If set to true, the plugin will try to tree-shake tracing statements out.
327+
* Note that the success of this depends on tree shaking generally being enabled in your build.
328+
* Attention: DO NOT enable this when you're using any performance monitoring-related SDK features (e.g. Sentry.startSpan()).
329+
*/
330+
excludeTracing?: boolean;
331+
332+
/**
333+
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay Shadow DOM recording functionality.
334+
* Note that the success of this depends on tree shaking being enabled in your build tooling.
335+
*
336+
* This option is safe to be used when you do not want to capture any Shadow DOM activity via Sentry Session Replay.
337+
*/
338+
excludeReplayShadowDom?: boolean;
339+
340+
/**
341+
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
342+
* Note that the success of this depends on tree shaking being enabled in your build tooling.
343+
*
344+
* You can safely do this when you do not want to capture any `iframe` activity via Sentry Session Replay.
345+
*/
346+
excludeReplayIframe?: boolean;
347+
348+
/**
349+
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay's Compression Web Worker.
350+
* Note that the success of this depends on tree shaking being enabled in your build tooling.
351+
*
352+
* **Notice:** You should only do use this option if you manually host a compression worker and configure it in your Sentry Session Replay integration config via the `workerUrl` option.
353+
*/
354+
excludeReplayWorker?: boolean;
355+
};
356+
310357
/**
311358
* Options related to react component name annotations.
312359
* Disabled by default, unless a value is set for this option.

packages/nextjs/src/config/webpack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let showedMissingGlobalErrorWarningMsg = false;
3737
* - `plugins`, to add SentryWebpackPlugin
3838
*
3939
* @param userNextConfig The user's existing nextjs config, as passed to `withSentryConfig`
40-
* @param userSentryWebpackPluginOptions The user's SentryWebpackPlugin config, as passed to `withSentryConfig`
40+
* @param userSentryOptions The user's SentryWebpackPlugin config, as passed to `withSentryConfig`
4141
* @returns The function to set as the nextjs config's `webpack` value
4242
*/
4343
export function constructWebpackConfigFunction(

packages/nextjs/src/config/webpackPluginOptions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ export function getWebpackPluginOptions(
9797
deploy: sentryBuildOptions.release?.deploy,
9898
...sentryBuildOptions.unstable_sentryWebpackPluginOptions?.release,
9999
},
100+
bundleSizeOptimizations: {
101+
...sentryBuildOptions.bundleSizeOptimizations,
102+
},
100103
_metaOptions: {
101104
loggerPrefixOverride: `[@sentry/nextjs - ${prefixInsert}]`,
102105
telemetry: {

packages/nextjs/test/config/webpack/webpackPluginOptions.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ describe('getWebpackPluginOptions()', () => {
5252
env: 'my-env',
5353
},
5454
},
55+
bundleSizeOptimizations: {
56+
excludeTracing: true,
57+
excludeReplayShadowDom: false,
58+
},
5559
});
5660

5761
expect(generatedPluginOptions.authToken).toBe('my-auth-token');
@@ -105,6 +109,10 @@ describe('getWebpackPluginOptions()', () => {
105109
},
106110
telemetry: false,
107111
url: 'my-url',
112+
bundleSizeOptimizations: {
113+
excludeTracing: true,
114+
excludeReplayShadowDom: false,
115+
},
108116
});
109117
});
110118

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8400,12 +8400,12 @@
84008400
unplugin "1.0.1"
84018401
uuid "^9.0.0"
84028402

8403-
"@sentry/webpack-plugin@2.20.1":
8404-
version "2.20.1"
8405-
resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-2.20.1.tgz#285d325a0a1bd0a534126b97e0190da9486ff7f6"
8406-
integrity sha512-U6LzoE09Ndt0OCWROoRaZqqIHGxyMRdKpBhbqoBqyyfVwXN/zGW3I/cWZ1e8rreiKFj+2+c7+X0kOS+NGMTUrg==
8403+
"@sentry/webpack-plugin@2.22.0":
8404+
version "2.22.0"
8405+
resolved "https://registry.yarnpkg.com/@sentry/webpack-plugin/-/webpack-plugin-2.22.0.tgz#f02e087fe9b318fefdb5441149ceadfc60407ae3"
8406+
integrity sha512-u2brctki0AMCoZksdAConQSYE6PokRVeZ4YYsbnJYkAi0KuaQnczsRwS9e2L0bK2CmZ7QdyYcrjaXHNlXaFDbQ==
84078407
dependencies:
8408-
"@sentry/bundler-plugin-core" "2.20.1"
8408+
"@sentry/bundler-plugin-core" "2.22.0"
84098409
unplugin "1.0.1"
84108410
uuid "^9.0.0"
84118411

0 commit comments

Comments
 (0)