Skip to content

Commit 5a55c67

Browse files
author
Luca Forstner
committed
Add tree shaking section for Next.js
1 parent fed5dbe commit 5a55c67

File tree

1 file changed

+26
-1
lines changed
  • src/platforms/javascript/common/troubleshooting

1 file changed

+26
-1
lines changed

src/platforms/javascript/common/troubleshooting/index.mdx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ export default {
441441
treeshake: "smallest", // recommended for best tree shaking results
442442
plugins: [
443443
replace({
444-
preventAssignment: false,
444+
preventAssignment: false, // not necessary because flags are not assigned to
445445
values: {
446446
__SENTRY_DEBUG__: false,
447447
},
@@ -450,3 +450,28 @@ export default {
450450
],
451451
};
452452
```
453+
454+
<PlatformSection supported={["javascript.nextjs"]}>
455+
456+
### Tree-shaking Debug Code with Next.js
457+
458+
To tree-shake Sentry debug code in Next.js projects, you can use webpack's [DefinePlugin](https://webpack.js.org/plugins/define-plugin/). The following Next.js configuration will replace all occurrences of `__SENTRY_DEBUG__` in your bundles with `false`:
459+
460+
```javascript {filename:next.config.js}
461+
const nextConfig = {
462+
webpack: (config, { webpack }) => {
463+
config.plugins.push(
464+
new webpack.DefinePlugin({
465+
__SENTRY_DEBUG__: false,
466+
})
467+
);
468+
469+
// return the modified config
470+
return config;
471+
},
472+
};
473+
```
474+
475+
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.
476+
477+
</PlatformSection>

0 commit comments

Comments
 (0)