-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathnext.config.ts
More file actions
190 lines (177 loc) · 6.06 KB
/
next.config.ts
File metadata and controls
190 lines (177 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import {codecovNextJSWebpackPlugin} from '@codecov/nextjs-webpack-plugin';
import {withSentryConfig} from '@sentry/nextjs';
import {redirects} from './redirects.js';
import {REMOTE_IMAGE_PATTERNS} from './src/config/images';
// Exclude build-time-only dependencies from serverless function bundles to stay under
// Vercel's 250MB limit. These packages are only needed during build to compile MDX and
// optimize assets. We use a local getMDXComponent (src/getMDXComponent.ts) instead of
// mdx-bundler/client to avoid CJS/ESM compatibility issues at runtime.
const sharedExcludes = [
'**/*.map',
'./.git/**/*',
'./apps/**/*',
'./.next/cache/mdx-bundler/**/*',
'./.next/cache/md-exports/**/*',
// Heavy build dependencies
'node_modules/@esbuild/**/*',
'node_modules/esbuild/**/*',
'node_modules/@aws-sdk/**/*',
'node_modules/@google-cloud/**/*',
'node_modules/prettier/**/*',
'node_modules/@prettier/**/*',
'node_modules/sharp/**/*',
'node_modules/mermaid/**/*',
// MDX processing dependencies (local getMDXComponent replaces mdx-bundler/client)
'node_modules/mdx-bundler/**/*',
'node_modules/rehype-preset-minify/**/*',
'node_modules/rehype-prism-plus/**/*',
'node_modules/rehype-prism-diff/**/*',
'node_modules/remark-gfm/**/*',
'node_modules/remark-mdx-images/**/*',
'node_modules/unified/**/*',
'node_modules/rollup/**/*',
];
const outputFileTracingExcludes = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
? {'/**/*': [...sharedExcludes, 'docs/**/*']}
: {
'/**/*': [...sharedExcludes, 'develop-docs/**/*'],
'/platform-redirect': [
'**/*.gif',
'public/mdx-images/**/*',
'public/og-images/**/*',
'**/*.pdf',
],
'\\[\\[\\.\\.\\.path\\]\\]': [
// Exclude docs to save ~156MB, allow specific files via outputFileTracingIncludes
'docs/**/*',
'node_modules/prettier/plugins',
'node_modules/rollup/dist',
'public/og-images/**/*',
],
'sitemap.xml': [
'public/mdx-images/**/*',
'public/og-images/**/*',
'**/*.gif',
'**/*.pdf',
'**/*.png',
],
};
// Explicitly include the pre-computed doc tree files for routes that need them at runtime.
// Both platform-redirect and [[...path]] need the doctree at runtime:
// - platform-redirect: dynamic route with searchParams
// - [[...path]]: calls getDocsRootNode() during prerendering (even though force-static)
// - sitemap.xml: uses getDocsRootNode() to extract all page paths
//
// Additionally, include specific doc files that may be accessed at runtime due to:
// - Error page rendering (when a static page fails to load)
// - Cold start edge cases during deployment
// - On-demand revalidation requests
// These are whitelisted individually to avoid including the entire docs/ directory.
const outputFileTracingIncludes = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
? {
'/platform-redirect': ['public/doctree-dev.json'],
'\\[\\[\\.\\.\\.path\\]\\]': ['public/doctree-dev.json'],
'sitemap.xml': ['public/doctree-dev.json'],
}
: {
'/platform-redirect': ['public/doctree.json'],
'\\[\\[\\.\\.\\.path\\]\\]': [
'public/doctree.json',
'docs/changelog.mdx',
'docs/platforms/index.mdx',
],
'sitemap.xml': ['public/doctree.json'],
};
if (
process.env.NODE_ENV !== 'development' &&
!process.env.NEXT_PUBLIC_SENTRY_DSN &&
!process.env.NEXT_TYPEGEN
) {
throw new Error(
'Missing required environment variable: NEXT_PUBLIC_SENTRY_DSN must be set in production'
);
}
/** @type {import('next').NextConfig} */
const nextConfig = {
pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx', 'mdx'],
trailingSlash: true,
serverExternalPackages: [
'rehype-preset-minify',
'esbuild',
'@esbuild/darwin-arm64',
'@esbuild/darwin-x64',
'@esbuild/linux-arm64',
'@esbuild/linux-x64',
'@esbuild/win32-x64',
// mdx-bundler fully excluded via outputFileTracingExcludes
'sharp',
'@aws-sdk/client-s3',
'@google-cloud/storage',
'prettier',
'@prettier/plugin-xml',
'mermaid',
],
outputFileTracingExcludes,
outputFileTracingIncludes,
images: {
contentDispositionType: 'inline', // "open image in new tab" instead of downloading
remotePatterns: REMOTE_IMAGE_PATTERNS,
},
webpack: (config, options) => {
config.plugins.push(
codecovNextJSWebpackPlugin({
enableBundleAnalysis: typeof process.env.CODECOV_TOKEN === 'string',
bundleName: 'sentry-docs',
uploadToken: process.env.CODECOV_TOKEN,
webpack: options.webpack,
})
);
return config;
},
env: {
// Inline NEXT_PUBLIC_DEVELOPER_DOCS into edge middleware at build time.
// Edge runtime doesn't have access to server env vars at request time.
DEVELOPER_DOCS: process.env.NEXT_PUBLIC_DEVELOPER_DOCS,
},
redirects,
rewrites: () => [
{
source: '/:path*.md',
destination: '/md-exports/:path*.md',
},
],
sassOptions: {
silenceDeprecations: ['legacy-js-api'],
},
};
module.exports = withSentryConfig(nextConfig, {
org: 'sentry',
project: process.env.NEXT_PUBLIC_DEVELOPER_DOCS ? 'develop-docs' : 'docs',
authToken: process.env.SENTRY_AUTH_TOKEN,
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers
tunnelRoute: '/sentry-tunnel',
// Suppresses source map uploading logs during build
silent: !process.env.CI,
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
webpack: {
treeshake: {
// Automatically tree-shake Sentry logger statements to reduce bundle size
removeDebugLogging: true,
},
// Enables automatic instrumentation of Vercel Cron Monitors
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,
reactComponentAnnotation: {
enabled: true,
},
unstable_sentryWebpackPluginOptions: {
applicationKey: 'sentry-docs',
},
},
_experimental: {
thirdPartyOriginStackFrames: true,
},
});