-
-
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
Changes from all commits
151ea78
aa147b7
a6579ce
f67322e
3ffba4b
5adda99
0094352
c58bc9a
1987f37
aae7dd5
acf7583
be647a9
bcdeaef
469e87b
1437ad6
ef40d1d
caa4d45
13e76ff
4895f43
f2f1547
0ec7cee
730c3e4
0365982
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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, | ||||||||||||||||||||||||||
|
Comment on lines
+43
to
+48
|
||||||||||||||||||||||||||
| // Tree shaking options... | |
| removeDebugLogging: false, | |
| removeTracing: false, | |
| excludeReplayIframe: false, | |
| excludeReplayShadowDOM: false, | |
| excludeReplayCompressionWorker: false, | |
| // Enable tree shaking by setting these options to true (defaults are all false). | |
| removeDebugLogging: true, | |
| removeTracing: true, | |
| excludeReplayIframe: true, | |
| excludeReplayShadowDOM: true, | |
| excludeReplayCompressionWorker: true, |
Uh oh!
There was an error while loading. Please reload this page.