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.26.0",
"@sentry/utils": "8.26.0",
"@sentry/vercel-edge": "8.26.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
44 changes: 44 additions & 0 deletions packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,50 @@ export type SentryBuildOptions = {
};
};

/**
* Options to configure various bundle size optimizations related to the Sentry SDK.
*/
bundleSizeOptimizations?: {
/**
* If set to `true`, the Sentry SDK will attempt to tree-shake (remove) any debugging code within itself during the build.
* 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 Sentry SDK will attempt to tree-shake (remove) code within itself that is related to tracing and performance monitoring.
* Note that the success of this depends on tree shaking being enabled in your build tooling.
* **Notice:** Do not enable this when you're using any performance monitoring-related SDK features (e.g. `Sentry.startTransaction()`).
*/
excludeTracing?: boolean;

/**
* 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.
* 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 Sentry SDK will attempt to tree-shake (remove) code related to the 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 Sentry SDK will attempt to tree-shake (remove) code related to the 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 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
17 changes: 17 additions & 0 deletions packages/nextjs/test/config/webpack/webpackPluginOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ describe('getWebpackPluginOptions()', () => {
});
});

it('forwards bundleSizeOptimization options', () => {
const buildContext = generateBuildContext({ isServer: false });
const generatedPluginOptions = getWebpackPluginOptions(buildContext, {
bundleSizeOptimizations: {
excludeTracing: true,
excludeReplayShadowDom: false,
},
});

expect(generatedPluginOptions).toMatchObject({
bundleSizeOptimizations: {
excludeTracing: true,
excludeReplayShadowDom: false,
},
});
});

it('returns the right `assets` and `ignore` values during the server build', () => {
const buildContext = generateBuildContext({ isServer: true });
const generatedPluginOptions = getWebpackPluginOptions(buildContext, {});
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8392,12 +8392,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