-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs(nextjs): added tree-shaking webpack config guide #15790
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
Draft
logaretm
wants to merge
21
commits into
master
Choose a base branch
from
awad/js-1222-add-treeshaking-options-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4f94e6f
docs(nextjs): added tree-shaking webpack config guide
logaretm 2edb039
docs: webpack casing
logaretm 815128f
docs: webpack casing
logaretm 6b6c635
docs: webpack casing
logaretm e120f42
fix: 404
logaretm 3fc9d13
docs: wording
logaretm 2573f5d
docs: wording
logaretm 009c57d
docs: wording
logaretm cfc44b2
docs: wording
logaretm 3d5d7f0
docs: title case
logaretm f537a36
chore: title case
logaretm f906b50
docs: improve wording
logaretm 4f82e3d
docs: wording consistency around the word tree-shake
logaretm ce8be43
fix: alert wording
logaretm 706bac2
docs: re-word to be next.js specific
logaretm baff090
docs: wording
logaretm c80a37f
chore: wording
logaretm 361c949
chore: wording
logaretm 6bac9dc
docs: alert wording
logaretm 00a3cdf
docs: debug logging info
logaretm 3d7f5d9
chore: docs
logaretm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
docs/platforms/javascript/guides/nextjs/configuration/tree-shaking.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- | ||
| title: Tree Shaking | ||
| sidebar_order: 70 | ||
| description: "Learn how to reduce Sentry bundle size by tree shaking unused code." | ||
| keywords: ["bundle size", "webpack", "Next.js", "debug"] | ||
| --- | ||
|
|
||
| The Sentry Next.js SDK supports [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) for webpack builds with some additional configurations. | ||
|
|
||
| If you want to minimize the bundle size of the Sentry SDK, we recommend reading through this page and applying the tree-shaking configurations shown. | ||
|
|
||
| <Alert> | ||
|
|
||
| This guide is only relevant if you're using webpack to build your Next.js application. Tree-shaking options are not supported for Turbopack builds at the moment. | ||
|
|
||
| </Alert> | ||
|
|
||
| ## Tree-Shaking Optional Code | ||
|
|
||
| The Sentry Next.js SDK includes code that isn't strictly required for basic error collection, such as debug logging and tracing functionality. While debug code is useful during development, it adds unnecessary weight to your production bundles. The Next.js SDK provides tree shaking options through the `withSentryConfig` function, allowing you to remove this optional code during the webpack build process. | ||
|
|
||
| <Alert> | ||
| Anything you don't import or use can be tree shaken by webpack. This means | ||
| that optional integrations like Session Replay, Browser Tracing, Browser | ||
| Profiling, and any unused utility methods won't be included in your bundle | ||
| unless you import and use them. The rest of this page covers ways to tree | ||
| shake internal SDK code, which you only need if you're using certain Sentry | ||
| features. | ||
| </Alert> | ||
|
|
||
| ## Tree-Shaking Options | ||
|
|
||
| To tree shake Sentry debug code in Next.js projects, use `webpack.treeshake` options in your build configuration, like in this example: | ||
|
|
||
| ```javascript {filename:next.config.(js|mjs)} | ||
| const nextConfig = { | ||
| // your next.js config | ||
| }; | ||
|
|
||
| withSentryConfig(nextConfig, { | ||
| webpack: { | ||
| treeshake: { | ||
| // Tree shaking options... | ||
| removeDebugLogging: false, | ||
| removeTracing: false, | ||
| excludeReplayIframe: false, | ||
| excludeReplayShadowDOM: false, | ||
| excludeReplayCompressionWorker: false, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| For more information on custom webpack configurations in Next.js, see [Custom Webpack Config](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config) in the Next.js docs. | ||
|
|
||
| The following sections cover each available tree-shaking option and how to configure them. | ||
|
|
||
| <SdkOption name="webpack.treeshake.removeDebugLogging" type="boolean" defaultValue="false"> | ||
|
|
||
| Setting this option to true will remove all Sentry SDK debug logging code (the console logs that appear when you set `debug: true` in your SDK configuration). This doesn't affect Sentry's Logs product (controlled by the `enableLogs` option) or your app's logging. | ||
|
|
||
| </SdkOption> | ||
|
|
||
| <SdkOption name="webpack.treeshake.removeTracing" type="boolean" defaultValue="false"> | ||
|
|
||
| Setting this option to `true` will remove all code related to tracing and performance monitoring. | ||
|
|
||
| <Alert> | ||
| You should not use any tracing-related SDK features (for example, | ||
| `Sentry.startSpan()`) when this option is enabled, also this option has no | ||
| effect if you did not add `browserTracingIntegration`. | ||
| </Alert> | ||
|
|
||
| </SdkOption> | ||
|
|
||
| <SdkOption name="webpack.treeshake.excludeReplayIframe" type="boolean" defaultValue="false"> | ||
|
|
||
| Setting this option to `true` will remove any SDK code related to capturing iframe content during [Session Replays](/platforms/javascript/session-replay/). This only applies when you've enabled `replayIntegration`. | ||
|
|
||
| </SdkOption> | ||
|
|
||
| <SdkOption name="webpack.treeshake.excludeReplayShadowDOM" type="boolean" defaultValue="false"> | ||
|
|
||
| Setting this option to `true` will remove any SDK code related to capturing shadow DOM elements during [Session Replays](/platforms/javascript/session-replay/). This only applies when you've enabled `replayIntegration`. | ||
|
|
||
| </SdkOption> | ||
|
|
||
| <SdkOption name="webpack.treeshake.excludeReplayCompressionWorker" type="boolean" defaultValue="false"> | ||
|
|
||
| Setting this option to `true` will remove any SDK code related to the included compression web worker for [Session Replay](/platforms/javascript/session-replay/). Enable this option if you want to host a compression worker yourself. See [Using a Custom Compression Worker](/platforms/javascript/session-replay/configuration/#using-a-custom-compression-worker) for details. This only applies when you've enabled `replayIntegration`. | ||
|
|
||
| **We don't recommend enabling this option unless you provide a custom worker URL**. | ||
|
|
||
| </SdkOption> | ||
|
|
||
| If you want to learn more about the available tree-shaking options and how to set them manually with different bundlers, see the [tree shaking documentation](/platforms/javascript/guides/react/configuration/tree-shaking/#tree-shaking-with-webpack) for the JavaScript SDK. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.