@@ -431,13 +431,8 @@ export function constructWebpackConfigFunction({
431431 }
432432 }
433433
434- if ( userSentryOptions . webpack ?. treeshake ?. debugLogging ) {
435- newConfig . plugins = newConfig . plugins || [ ] ;
436- newConfig . plugins . push (
437- new buildContext . webpack . DefinePlugin ( {
438- __SENTRY_DEBUG__ : false ,
439- } ) ,
440- ) ;
434+ if ( userSentryOptions . webpack ?. treeshake ) {
435+ setupTreeshakingFromConfig ( userSentryOptions , newConfig , buildContext ) ;
441436 }
442437
443438 // We inject a map of dependencies that the nextjs app has, as we cannot reliably extract them at runtime, sadly
@@ -915,3 +910,39 @@ function _getModules(projectDir: string): Record<string, string> {
915910 return { } ;
916911 }
917912}
913+
914+ /**
915+ * Sets up the tree-shaking flags based on the user's configuration.
916+ * https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/
917+ */
918+ function setupTreeshakingFromConfig (
919+ userSentryOptions : SentryBuildOptions ,
920+ newConfig : WebpackConfigObjectWithModuleRules ,
921+ buildContext : BuildContext ,
922+ ) : void {
923+ const defines : Record < string , boolean > = { } ;
924+
925+ newConfig . plugins = newConfig . plugins || [ ] ;
926+
927+ if ( userSentryOptions . webpack ?. treeshake ?. debugLogging ) {
928+ defines . __SENTRY_DEBUG__ = false ;
929+ }
930+
931+ if ( userSentryOptions . webpack ?. treeshake ?. tracing ) {
932+ defines . __SENTRY_TRACING__ = false ;
933+ }
934+
935+ if ( userSentryOptions . webpack ?. treeshake ?. excludeReplayIframe ) {
936+ defines . __RRWEB_EXCLUDE_IFRAME__ = true ;
937+ }
938+
939+ if ( userSentryOptions . webpack ?. treeshake ?. excludeReplayShadowDOM ) {
940+ defines . __RRWEB_EXCLUDE_SHADOW_DOM__ = true ;
941+ }
942+
943+ if ( userSentryOptions . webpack ?. treeshake ?. excludeReplayCompressionWorker ) {
944+ defines . __SENTRY_EXCLUDE_REPLAY_WORKER__ = true ;
945+ }
946+
947+ newConfig . plugins . push ( new buildContext . webpack . DefinePlugin ( defines ) ) ;
948+ }
0 commit comments