Skip to content

Commit 34654f1

Browse files
committed
distinguish between serverless and non-serverless builds
1 parent 729dfff commit 34654f1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/nextjs/src/config/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type ExportedNextConfig = NextConfigObject | NextConfigFunction;
99
export type NextConfigObject = {
1010
// custom webpack options
1111
webpack?: WebpackConfigFunction;
12+
// whether to build serverless functions for all pages, not just API routes
13+
target?: 'server' | 'experimental-serverless-trace';
1214
sentry?: {
1315
disableServerWebpackPlugin?: boolean;
1416
disableClientWebpackPlugin?: boolean;

packages/nextjs/src/config/webpack.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,17 @@ function getWebpackPluginOptions(
242242
buildContext: BuildContext,
243243
userPluginOptions: Partial<SentryWebpackPluginOptions>,
244244
): SentryWebpackPluginOptions {
245-
const { isServer, dir: projectDir, buildId, dev: isDev } = buildContext;
245+
const { isServer, dir: projectDir, buildId, dev: isDev, config: nextConfig } = buildContext;
246246

247+
const isServerless = nextConfig.target === 'experimental-serverless-trace';
247248
const hasSentryProperties = fs.existsSync(path.resolve(projectDir, 'sentry.properties'));
248249

249-
const serverInclude = [
250-
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
251-
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
252-
{ paths: ['.next/serverless/'], urlPrefix: '~/_next/serverless' },
253-
];
250+
const serverInclude = isServerless
251+
? [{ paths: ['.next/serverless/'], urlPrefix: '~/_next/serverless' }]
252+
: [
253+
{ paths: ['.next/server/chunks/'], urlPrefix: '~/_next/server/chunks' },
254+
{ paths: ['.next/server/pages/'], urlPrefix: '~/_next/server/pages' },
255+
];
254256
const clientInclude = [{ paths: ['.next/static/chunks/pages'], urlPrefix: '~/_next/static/chunks/pages' }];
255257

256258
const defaultPluginOptions = dropUndefinedKeys({

0 commit comments

Comments
 (0)