Skip to content

Commit

Permalink
exclude build-time files
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Nov 21, 2022
1 parent 9e6fd1a commit 80d2fcc
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/nextjs/src/config/webpack.ts
@@ -1,10 +1,11 @@
/* eslint-disable max-lines */
import { getSentryRelease } from '@sentry/node';
import { deepReadDirSync, getSentryRelease } from '@sentry/node';
import { arrayify, dropUndefinedKeys, escapeStringForRegex, logger, stringMatchesSomePattern } from '@sentry/utils';
import { default as SentryWebpackPlugin } from '@sentry/webpack-plugin';
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';
import { WebpackPluginInstance } from 'webpack';

import {
BuildContext,
Expand Down Expand Up @@ -100,6 +101,28 @@ export function constructWebpackConfigFunction(
],
});
}

// Prevent `@vercel/nft` (which nextjs uses to determine which files are needed when packaging up a lambda) from
// including any of our build-time code or dependencies. (Otherwise it'll include files like this one and even the
// entirety of rollup and sucrase.)
const nftPlugin = newConfig.plugins?.find((plugin: WebpackPluginInstance) => {
const proto = Object.getPrototypeOf(plugin) as WebpackPluginInstance;
return proto.constructor.name === 'TraceEntryPointsPlugin';
}) as WebpackPluginInstance & { excludeFiles: string[] };
if (nftPlugin) {
const nextjsPackageRoot = path.dirname(require.resolve('@sentry/nextjs'));
const nextjsPackageConfigDir = path.join(nextjsPackageRoot, 'config');
const excludedNextjsPackageFiles = deepReadDirSync(nextjsPackageConfigDir).map(file =>
path.join(nextjsPackageConfigDir, file),
);

nftPlugin.excludeFiles.push(...excludedNextjsPackageFiles);
} else {
__DEBUG_BUILD__ &&
logger.warn(
'Unable to exclude Sentry build-time helpers from nft files. Could not find `TraceEntryPointsPlugin`.',
);
}
}

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

0 comments on commit 80d2fcc

Please sign in to comment.