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