Skip to content
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

feat(nextjs): Add bundleSizeOptimizations to build options #13323

Merged
merged 11 commits into from
Sep 2, 2024
2 changes: 1 addition & 1 deletion packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@sentry/types": "8.25.0",
"@sentry/utils": "8.25.0",
"@sentry/vercel-edge": "8.25.0",
"@sentry/webpack-plugin": "2.20.1",
"@sentry/webpack-plugin": "2.22.0",
"chalk": "3.0.0",
"resolve": "1.22.8",
"rollup": "3.29.4",
Expand Down
47 changes: 47 additions & 0 deletions packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,53 @@ export type SentryBuildOptions = {
};
};

/**
* Options for the Sentry Webpack plugin to customize bundle size optimizations.
*
* These options are always read from the `sentryAstro` integration.
* Do not define them in the `sentry.client.config.(js|ts)` or `sentry.server.config.(js|ts)` files.
Copy link
Member

@lforst lforst Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks off (astro != nextjs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh thanks, that's a copy paste error

*/
bundleSizeOptimizations?: {
/**
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* Setting this option to `true` will disable features like the SDK's `debug` option.
*/
excludeDebugStatements?: boolean;

/**
* If set to true, the plugin will try to tree-shake tracing statements out.
* Note that the success of this depends on tree shaking generally being enabled in your build.
* Attention: DO NOT enable this when you're using any performance monitoring-related SDK features (e.g. Sentry.startSpan()).
*/
excludeTracing?: boolean;

/**
* 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.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* This option is safe to be used when you do not want to capture any Shadow DOM activity via Sentry Session Replay.
*/
excludeReplayShadowDom?: boolean;

/**
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* You can safely do this when you do not want to capture any `iframe` activity via Sentry Session Replay.
*/
excludeReplayIframe?: boolean;

/**
* 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.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
*
* **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.
*/
excludeReplayWorker?: boolean;
};

/**
* Options related to react component name annotations.
* Disabled by default, unless a value is set for this option.
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let showedMissingGlobalErrorWarningMsg = false;
* - `plugins`, to add SentryWebpackPlugin
*
* @param userNextConfig The user's existing nextjs config, as passed to `withSentryConfig`
* @param userSentryWebpackPluginOptions The user's SentryWebpackPlugin config, as passed to `withSentryConfig`
* @param userSentryOptions The user's SentryWebpackPlugin config, as passed to `withSentryConfig`
* @returns The function to set as the nextjs config's `webpack` value
*/
export function constructWebpackConfigFunction(
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/src/config/webpackPluginOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export function getWebpackPluginOptions(
deploy: sentryBuildOptions.release?.deploy,
...sentryBuildOptions.unstable_sentryWebpackPluginOptions?.release,
},
bundleSizeOptimizations: {
...sentryBuildOptions.bundleSizeOptimizations,
},
_metaOptions: {
loggerPrefixOverride: `[@sentry/nextjs - ${prefixInsert}]`,
telemetry: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ describe('getWebpackPluginOptions()', () => {
env: 'my-env',
},
},
bundleSizeOptimizations: {
excludeTracing: true,
excludeReplayShadowDom: false,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Any reason we added this here? I don't see any changes to assertions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense to separate this. I created another test just for those options.

});

expect(generatedPluginOptions.authToken).toBe('my-auth-token');
Expand Down Expand Up @@ -105,6 +109,10 @@ describe('getWebpackPluginOptions()', () => {
},
telemetry: false,
url: 'my-url',
bundleSizeOptimizations: {
excludeTracing: true,
excludeReplayShadowDom: false,
},
});
});

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8400,12 +8400,12 @@
unplugin "1.0.1"
uuid "^9.0.0"

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

Expand Down
Loading