Skip to content

Commit 1efba79

Browse files
committed
only set devtool and add webpack plugin when plugin not disabled
1 parent e964904 commit 1efba79

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,6 @@ export function constructWebpackConfigFunction(
6969
newConfig = userNextConfig.webpack(newConfig, options);
7070
}
7171

72-
// Ensure quality source maps in production. (Source maps aren't uploaded in dev, and besides, Next doesn't let you
73-
// change this is dev even if you want to - see
74-
// https://github.com/vercel/next.js/blob/master/errors/improper-devtool.md.)
75-
if (!options.dev) {
76-
// TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see
77-
// https://webpack.js.org/plugins/source-map-dev-tool-plugin/)
78-
// TODO Give user option to use `hidden-source-map` ?
79-
newConfig.devtool = 'source-map';
80-
}
81-
8272
// Tell webpack to inject user config files (containing the two `Sentry.init()` calls) into the appropriate output
8373
// bundles. Store a separate reference to the original `entry` value to avoid an infinite loop. (If we don't do
8474
// this, we'll have a statement of the form `x.y = () => f(x.y)`, where one of the things `f` does is call `x.y`.
@@ -90,19 +80,36 @@ export function constructWebpackConfigFunction(
9080
const origEntryProperty = newConfig.entry;
9181
newConfig.entry = async () => addSentryToEntryProperty(origEntryProperty, options.isServer);
9282

93-
// Add the Sentry plugin, which uploads source maps to Sentry when not in dev
94-
checkWebpackPluginOverrides(userSentryWebpackPluginOptions);
95-
newConfig.plugins = newConfig.plugins || [];
96-
newConfig.plugins.push(
97-
// @ts-ignore Our types for the plugin are messed up somehow - TS wants this to be `SentryWebpackPlugin.default`,
98-
// but that's not actually a thing
99-
new SentryWebpackPlugin({
100-
dryRun: options.dev,
101-
release: getSentryRelease(options.buildId),
102-
...defaultSentryWebpackPluginOptions,
103-
...userSentryWebpackPluginOptions,
104-
}),
105-
);
83+
// Enable the Sentry plugin (which uploads source maps to Sentry when not in dev) by default
84+
const enableWebpackPlugin = options.isServer
85+
? !userNextConfig.sentry?.disableServerWebpackPlugin
86+
: !userNextConfig.sentry?.disableClientWebpackPlugin;
87+
88+
if (enableWebpackPlugin) {
89+
// TODO Handle possibility that user is using `SourceMapDevToolPlugin` (see
90+
// https://webpack.js.org/plugins/source-map-dev-tool-plugin/)
91+
// TODO Give user option to use `hidden-source-map` ?
92+
93+
// Next doesn't let you change this is dev even if you want to - see
94+
// https://github.com/vercel/next.js/blob/master/errors/improper-devtool.md
95+
if (!options.dev) {
96+
newConfig.devtool = 'source-map';
97+
}
98+
99+
checkWebpackPluginOverrides(userSentryWebpackPluginOptions);
100+
101+
newConfig.plugins = newConfig.plugins || [];
102+
newConfig.plugins.push(
103+
// @ts-ignore Our types for the plugin are messed up somehow - TS wants this to be `SentryWebpackPlugin.default`,
104+
// but that's not actually a thing
105+
new SentryWebpackPlugin({
106+
dryRun: options.dev,
107+
release: getSentryRelease(options.buildId),
108+
...defaultSentryWebpackPluginOptions,
109+
...userSentryWebpackPluginOptions,
110+
}),
111+
);
112+
}
106113

107114
return newConfig;
108115
};

0 commit comments

Comments
 (0)