forked from getsentry/sentry-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
211 lines (197 loc) · 6.99 KB
/
next.config.ts
File metadata and controls
211 lines (197 loc) · 6.99 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import {codecovNextJSWebpackPlugin} from '@codecov/nextjs-webpack-plugin';
import {withSentryConfig} from '@sentry/nextjs';
import {REMOTE_IMAGE_PATTERNS} from './src/config/images';
import {redirects} from './redirects.js';
// Exclude build-time-only dependencies from serverless function bundles to stay under
// Vercel's 250MB limit. These packages (esbuild, mdx-bundler, sharp, etc.) are only
// needed during the build process to compile MDX and optimize assets. The compiled
// output is used at runtime, so bundling these ~150-200MB of dependencies would bloat
// functions unnecessarily and cause deployment failures.
//
// Note: mdx-bundler/client (getMDXComponent) is a tiny runtime module needed by
// app/[[...path]]/page.tsx, so we exclude only the build parts (dist/!(client)*).
const outputFileTracingExcludes = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
? {
'/**/*': [
'**/*.map',
'./.git/**/*',
'./apps/**/*',
'./.next/cache/mdx-bundler/**/*',
'./.next/cache/md-exports/**/*',
'docs/**/*',
// Exclude 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/**/*',
// Exclude MDX processing dependencies (but keep mdx-bundler/client for runtime)
'node_modules/mdx-bundler/dist/!(client*)',
'node_modules/mdx-bundler/node_modules/**/*',
'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/**/*',
],
}
: {
'/**/*': [
'**/*.map',
'./.git/**/*',
'./.next/cache/mdx-bundler/**/*',
'./.next/cache/md-exports/**/*',
'./apps/**/*',
'develop-docs/**/*',
// Exclude 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/**/*',
// Exclude MDX processing dependencies (but keep mdx-bundler/client for runtime)
'node_modules/mdx-bundler/dist/!(client*)',
'node_modules/mdx-bundler/node_modules/**/*',
'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/**/*',
],
'/platform-redirect': [
'**/*.gif',
'public/mdx-images/**/*',
'public/og-images/**/*',
'**/*.pdf',
],
'\\[\\[\\.\\.\\.path\\]\\]': [
// Exclude docs to save ~156MB, but allow specific files via outputFileTracingIncludes
// for pages that may be accessed at runtime (error pages, cold starts, etc.)
'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)
//
// 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'],
}
: {
'/platform-redirect': ['public/doctree.json'],
'\\[\\[\\.\\.\\.path\\]\\]': [
'public/doctree.json',
'docs/changelog.mdx',
'docs/platforms/index.mdx',
],
};
if (process.env.NODE_ENV !== 'development' && !process.env.NEXT_PUBLIC_SENTRY_DSN) {
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',
'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: {
// This is used on middleware
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,
// 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,
// Automatically tree-shake Sentry logger statements to reduce bundle size
disableLogger: 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,
},
});