Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nextjs): added webpack treeshaking flags as config#18359
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
46f9d29a003650f72b6e5165d126a7a1c589f83e72d9a4fb9825cf35File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -428,13 +428,8 @@ export function constructWebpackConfigFunction({ | ||
| } | ||
| } | ||
| if (userSentryOptions.webpack?.treeshake?.removeDebugLogging) { | ||
| newConfig.plugins = newConfig.plugins || []; | ||
| newConfig.plugins.push( | ||
| new buildContext.webpack.DefinePlugin({ | ||
| __SENTRY_DEBUG__: false, | ||
| }), | ||
| ); | ||
| if (userSentryOptions.webpack?.treeshake) { | ||
| setupTreeshakingFromConfig(userSentryOptions, newConfig, buildContext); | ||
| } | ||
| // We inject a map of dependencies that the nextjs app has, as we cannot reliably extract them at runtime, sadly | ||
| @@ -912,3 +907,42 @@ function _getModules(projectDir: string): Record<string, string> { | ||
| return {}; | ||
| } | ||
| } | ||
| /** | ||
| * Sets up the tree-shaking flags based on the user's configuration. | ||
| * https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/ | ||
| */ | ||
| function setupTreeshakingFromConfig( | ||
| userSentryOptions: SentryBuildOptions, | ||
| newConfig: WebpackConfigObjectWithModuleRules, | ||
| buildContext: BuildContext, | ||
| ): void { | ||
| const defines: Record<string, boolean> = {}; | ||
| newConfig.plugins = newConfig.plugins || []; | ||
| if (userSentryOptions.webpack?.treeshake?.removeDebugLogging) { | ||
| defines.__SENTRY_DEBUG__ = false; | ||
| } | ||
| if (userSentryOptions.webpack?.treeshake?.removeTracing) { | ||
| defines.__SENTRY_TRACING__ = false; | ||
| } | ||
| if (userSentryOptions.webpack?.treeshake?.excludeReplayIframe) { | ||
| defines.__RRWEB_EXCLUDE_IFRAME__ = true; | ||
| } | ||
| if (userSentryOptions.webpack?.treeshake?.excludeReplayShadowDOM) { | ||
| defines.__RRWEB_EXCLUDE_SHADOW_DOM__ = true; | ||
| } | ||
| if (userSentryOptions.webpack?.treeshake?.excludeReplayCompressionWorker) { | ||
| defines.__SENTRY_EXCLUDE_REPLAY_WORKER__ = true; | ||
| } | ||
| // Only add DefinePlugin if there are actual defines to set | ||
| if (Object.keys(defines).length > 0) { | ||
| newConfig.plugins.push(new buildContext.webpack.DefinePlugin(defines)); | ||
| } | ||
| } | ||
logaretm marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.