Skip to content

Commit f1f2fe0

Browse files
committed
exclude build-time files
1 parent 5e8664c commit f1f2fe0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/nextjs/src/config/webpack.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
55
import * as chalk from 'chalk';
66
import * as fs from 'fs';
77
import * as path from 'path';
8+
import { WebpackPluginInstance } from 'webpack';
89

910
import {
1011
BuildContext,
@@ -100,6 +101,22 @@ export function constructWebpackConfigFunction(
100101
],
101102
});
102103
}
104+
105+
// Prevent `@vercel/nft` (which nextjs uses to determine which files are needed when packaging up a lambda) from
106+
// including any of our build-time code or dependencies. (Otherwise it'll include files like this one and even the
107+
// entirety of rollup and sucrase.)
108+
const nftPlugin = newConfig.plugins?.find((plugin: WebpackPluginInstance) => {
109+
const proto = Object.getPrototypeOf(plugin) as WebpackPluginInstance;
110+
return proto.constructor.name === 'TraceEntryPointsPlugin';
111+
}) as WebpackPluginInstance & { excludeFiles: string[] };
112+
if (nftPlugin) {
113+
nftPlugin.excludeFiles.push(path.join(__dirname, 'withSentryConfig.js'));
114+
} else {
115+
__DEBUG_BUILD__ &&
116+
logger.warn(
117+
'Unable to exclude Sentry build-time helpers from nft files. Could not find `TraceEntryPointsPlugin`.',
118+
);
119+
}
103120
}
104121

105122
// The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users

0 commit comments

Comments
 (0)