Skip to content

Commit 318c163

Browse files
s1gr1dlforst
andauthored
feat(nextjs): Add bundleSizeOptimizations to build options (#13323)
Extend options that can be added to `withSentryConfig` part of #13012 --------- Co-authored-by: Luca Forstner <[email protected]>
1 parent 01165db commit 318c163

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

packages/nextjs/src/config/types.ts

+44
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,50 @@ export type SentryBuildOptions = {
307307
};
308308
};
309309

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

packages/nextjs/src/config/webpack.ts

+1-1
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

+3
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

+17
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ describe('getWebpackPluginOptions()', () => {
108108
});
109109
});
110110

111+
it('forwards bundleSizeOptimization options', () => {
112+
const buildContext = generateBuildContext({ isServer: false });
113+
const generatedPluginOptions = getWebpackPluginOptions(buildContext, {
114+
bundleSizeOptimizations: {
115+
excludeTracing: true,
116+
excludeReplayShadowDom: false,
117+
},
118+
});
119+
120+
expect(generatedPluginOptions).toMatchObject({
121+
bundleSizeOptimizations: {
122+
excludeTracing: true,
123+
excludeReplayShadowDom: false,
124+
},
125+
});
126+
});
127+
111128
it('returns the right `assets` and `ignore` values during the server build', () => {
112129
const buildContext = generateBuildContext({ isServer: true });
113130
const generatedPluginOptions = getWebpackPluginOptions(buildContext, {});

0 commit comments

Comments
 (0)