Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/nextjs/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GLOBAL_OBJ } from '@sentry/utils';
import type { SentryCliPluginOptions } from '@sentry/webpack-plugin';
import type { WebpackPluginInstance } from 'webpack';
import type { DefinePlugin, WebpackPluginInstance } from 'webpack';

export type SentryWebpackPluginOptions = SentryCliPluginOptions;
export type SentryWebpackPlugin = WebpackPluginInstance & { options: SentryWebpackPluginOptions };
Expand Down Expand Up @@ -128,6 +128,11 @@ export type UserSentryOptions = {
* NOTE: This feature only works with Next.js 11+
*/
tunnelRoute?: string;

/**
* Tree shakes Sentry SDK logger statements from the bundle.
*/
disableLogger?: boolean;
};

export type NextConfigFunction = (phase: string, defaults: { defaultConfig: NextConfigObject }) => NextConfigObject;
Expand Down Expand Up @@ -167,7 +172,10 @@ export type BuildContext = {
dir: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config: any;
webpack: { version: string };
webpack: {
version: string;
DefinePlugin: typeof DefinePlugin;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
defaultLoaders: any;
totalPages: number;
Expand Down
9 changes: 9 additions & 0 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ export function constructWebpackConfigFunction(
}
}

if (userSentryOptions.disableLogger) {
newConfig.plugins = newConfig.plugins || [];
newConfig.plugins.push(
new buildContext.webpack.DefinePlugin({
__SENTRY_DEBUG__: false,
}),
);
}

return newConfig;
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/test/config/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function getBuildContext(
distDir: '.next',
...materializedNextConfig,
} as NextConfigObject,
webpack: { version: webpackVersion },
webpack: { version: webpackVersion, DefinePlugin: class {} as any },
defaultLoaders: true,
totalPages: 2,
isServer: buildTarget === 'server' || buildTarget === 'edge',
Expand Down