Skip to content

Commit 5605133

Browse files
committed
exclude unneeded tracing files from bundles
1 parent 045707b commit 5605133

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/nextjs/src/config/webpack.ts

+16
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ export function constructWebpackConfigFunction(
6060
const origEntryProperty = newConfig.entry;
6161
newConfig.entry = async () => addSentryToEntryProperty(origEntryProperty, buildContext);
6262

63+
// In webpack 5, you can get webpack to replace any module you'd like with an empty object, just by setting its
64+
// `resolve.alias` value to `false`. Not much of our code is neatly separated into "things node needs" and "things
65+
// the browser needs," but where it is, we can save ~1.6 kb in eventual bundle size by excluding code we know we
66+
// don't need. (Normally this would only matter for the client side, but because vercel turns backend code into
67+
// serverless functions, it's worthwhile to do it for both.)
68+
if (buildContext.webpack.version.startsWith('5')) {
69+
const excludedTracingDir = buildContext.isServer ? 'browser' : 'integrations/node';
70+
newConfig.resolve = {
71+
...newConfig.resolve,
72+
alias: {
73+
...newConfig.resolve?.alias,
74+
[path.resolve(buildContext.dir, `./node_modules/@sentry/tracing/esm/${excludedTracingDir}`)]: false,
75+
},
76+
};
77+
}
78+
6379
// Enable the Sentry plugin (which uploads source maps to Sentry when not in dev) by default
6480
const enableWebpackPlugin = buildContext.isServer
6581
? !userNextConfig.sentry?.disableServerWebpackPlugin

0 commit comments

Comments
 (0)