Skip to content

Commit 45362c6

Browse files
committed
feat: enable tree shaking of Sentry SDK debug code
1 parent 4298bdb commit 45362c6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/core/hooks.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { resolve, posix } from 'path'
22
import merge from 'lodash.mergewith'
3+
import { DefinePlugin } from 'webpack'
34
import * as Sentry from '@sentry/node'
45
import { canInitialize, clientSentryEnabled, envToBool, serverSentryEnabled } from './utils'
56
import { resolveRelease, resolveClientOptions, resolveServerOptions } from './options'
@@ -42,6 +43,16 @@ export async function buildHook (moduleContainer, moduleOptions, logger) {
4243
options: { release },
4344
})
4445
}
46+
47+
// Tree shake debugging code if not running in dev mode and Sentry debug option is not enabled on the client.
48+
if (!clientOptions.dev && !clientOptions.config.debug) {
49+
moduleContainer.options.build.plugins = moduleContainer.options.build.plugins || []
50+
moduleContainer.options.build.plugins.push(
51+
new DefinePlugin({
52+
__SENTRY_DEBUG__: 'false',
53+
}),
54+
)
55+
}
4556
}
4657

4758
/**

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"dev:fixture:build": "node ./node_modules/nuxt/bin/nuxt.js build -c ./test/fixture/default/nuxt.config.js",
2727
"dev:fixture:start": "node ./node_modules/nuxt/bin/nuxt.js start -c ./test/fixture/default/nuxt.config.js",
2828
"dev:generate": "nuxt generate -c ./test/fixture/default/nuxt.config.js --force-build",
29+
"analyze": "node ./node_modules/nuxt/bin/nuxt.js build --analyze -c ./test/fixture/default/nuxt.config.js",
2930
"lint": "eslint --ext .vue,.js,.ts .",
3031
"lint:fix": "eslint --ext .vue,.js,.ts . --fix",
3132
"lint:fixture": "eslint --ext .vue,.js --no-ignore 'test/fixture/*/.nuxt/sentry.*'",

0 commit comments

Comments
 (0)