|
| 1 | +import { isBuild } from '../utils/isBuild'; |
1 | 2 | import type {
|
2 | 3 | ExportedNextConfig,
|
3 | 4 | NextConfigFunction,
|
4 | 5 | NextConfigObject,
|
5 | 6 | NextConfigObjectWithSentry,
|
6 | 7 | SentryWebpackPluginOptions,
|
7 | 8 | } from './types';
|
8 |
| -import { constructWebpackConfigFunction } from './webpack'; |
9 | 9 |
|
10 | 10 | /**
|
11 | 11 | * Add Sentry options to the config to be exported from the user's `next.config.js` file.
|
@@ -46,8 +46,18 @@ function getFinalConfigObject(
|
46 | 46 | // Remind TS that there's now no `sentry` property
|
47 | 47 | const userNextConfigObject = incomingUserNextConfigObject as NextConfigObject;
|
48 | 48 |
|
49 |
| - return { |
50 |
| - ...userNextConfigObject, |
51 |
| - webpack: constructWebpackConfigFunction(userNextConfigObject, userSentryWebpackPluginOptions, userSentryOptions), |
52 |
| - }; |
| 49 | + // In order to prevent all of our build-time code from being bundled in people's route-handling serverless functions, |
| 50 | + // we exclude `webpack.ts` and all of its dependencies from nextjs's `@vercel/nft` filetracing. We therefore need to |
| 51 | + // make sure that we only require it at build time. |
| 52 | + if (isBuild()) { |
| 53 | + // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 54 | + const { constructWebpackConfigFunction } = require('./webpack'); |
| 55 | + return { |
| 56 | + ...userNextConfigObject, |
| 57 | + webpack: constructWebpackConfigFunction(userNextConfigObject, userSentryWebpackPluginOptions, userSentryOptions), |
| 58 | + }; |
| 59 | + } |
| 60 | + |
| 61 | + // At runtime, we just return the user's config untouched. |
| 62 | + return userNextConfigObject; |
53 | 63 | }
|
0 commit comments