-
Notifications
You must be signed in to change notification settings - Fork 26.1k
/
config-shared.ts
517 lines (467 loc) · 15 KB
/
config-shared.ts
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
import os from 'os'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import { Header, Redirect, Rewrite } from '../lib/load-custom-routes'
import {
ImageConfig,
ImageConfigComplete,
imageConfigDefault,
RemotePattern,
} from '../shared/lib/image-config'
export type PageRuntime = 'nodejs' | 'edge' | undefined
export type NextConfigComplete = Required<NextConfig> & {
images: Required<ImageConfigComplete>
typescript: Required<TypeScriptConfig>
configOrigin?: string
configFile?: string
configFileName: string
}
export interface I18NConfig {
defaultLocale: string
domains?: DomainLocale[]
localeDetection?: false
locales: string[]
}
export interface DomainLocale {
defaultLocale: string
domain: string
http?: true
locales?: string[]
}
export interface ESLintConfig {
/** Only run ESLint on these directories with `next lint` and `next build`. */
dirs?: string[]
/** Do not run ESLint during production builds (`next build`). */
ignoreDuringBuilds?: boolean
}
export interface TypeScriptConfig {
/** Do not run TypeScript during production builds (`next build`). */
ignoreBuildErrors?: boolean
/** Relative path to a custom tsconfig file */
tsconfigPath?: string
}
export interface WebpackConfigContext {
/** Next.js root directory */
dir: string
/** Indicates if the compilation will be done in development */
dev: boolean
/** It's `true` for server-side compilation, and `false` for client-side compilation */
isServer: boolean
/** The build id, used as a unique identifier between builds */
buildId: string
/** The next.config.js merged with default values */
config: NextConfigComplete
/** Default loaders used internally by Next.js */
defaultLoaders: {
/** Default babel-loader configuration */
babel: any
}
/** Number of total Next.js pages */
totalPages: number
/** The webpack configuration */
webpack: any
/** The current server runtime */
nextRuntime?: 'nodejs' | 'edge'
}
export interface NextJsWebpackConfig {
(
/** Existing Webpack config */
config: any,
context: WebpackConfigContext
): any
}
export interface ExperimentalConfig {
newNextLinkBehavior?: boolean
disablePostcssPresetEnv?: boolean
swcMinify?: boolean
swcFileReading?: boolean
cpus?: number
sharedPool?: boolean
plugins?: boolean
profiling?: boolean
isrFlushToDisk?: boolean
reactMode?: 'legacy' | 'concurrent' | 'blocking'
workerThreads?: boolean
pageEnv?: boolean
optimizeCss?: boolean
nextScriptWorkers?: boolean
scrollRestoration?: boolean
externalDir?: boolean
conformance?: boolean
rootDir?: boolean
amp?: {
optimizer?: any
validator?: string
skipValidation?: boolean
}
reactRoot?: boolean
disableOptimizedLoading?: boolean
gzipSize?: boolean
craCompat?: boolean
esmExternals?: boolean | 'loose'
isrMemoryCacheSize?: number
runtime?: Exclude<PageRuntime, undefined>
serverComponents?: boolean
fullySpecified?: boolean
urlImports?: NonNullable<webpack5.Configuration['experiments']>['buildHttp']
outputFileTracingRoot?: string
outputStandalone?: boolean
images?: {
layoutRaw: boolean
remotePatterns: RemotePattern[]
}
middlewareSourceMaps?: boolean
emotion?:
| boolean
| {
sourceMap?: boolean
autoLabel?: 'dev-only' | 'always' | 'never'
labelFormat?: string
}
modularizeImports?: Record<
string,
{
transform: string
preventFullImport?: boolean
skipDefaultConversion?: boolean
}
>
swcTraceProfiling?: boolean
}
/**
* Next configuration object
* @see [configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/introduction)
*/
export interface NextConfig extends Record<string, any> {
/**
* Internationalization configuration
*
* @see [Internationalization docs](https://nextjs.org/docs/advanced-features/i18n-routing)
*/
i18n?: I18NConfig | null
/**
* @since version 11
* @see [ESLint configuration](https://nextjs.org/docs/basic-features/eslint)
*/
eslint?: ESLintConfig
/**
* @see [Next.js TypeScript documentation](https://nextjs.org/docs/basic-features/typescript)
*/
typescript?: TypeScriptConfig
/**
* Headers allow you to set custom HTTP headers for an incoming request path.
*
* @see [Headers configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/headers)
*/
headers?: () => Promise<Header[]>
/**
* Rewrites allow you to map an incoming request path to a different destination path.
*
* @see [Rewrites configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/rewrites)
*/
rewrites?: () => Promise<
| Rewrite[]
| {
beforeFiles: Rewrite[]
afterFiles: Rewrite[]
fallback: Rewrite[]
}
>
/**
* Redirects allow you to redirect an incoming request path to a different destination path.
*
* @see [Redirects configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/redirects)
*/
redirects?: () => Promise<Redirect[]>
/**
* @deprecated This option has been removed as webpack 5 is now default
* @see [Next.js webpack 5 documentation](https://nextjs.org/docs/messages/webpack5) for upgrading guidance.
*/
webpack5?: false
/**
* @see [Moment.js locales excluded by default](https://nextjs.org/docs/upgrading#momentjs-locales-excluded-by-default)
*/
excludeDefaultMomentLocales?: boolean
/**
* Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case
*
* @see [Custom Webpack Config documentation](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config)
*/
webpack?: NextJsWebpackConfig | null
/**
* By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash.
*
* @default false
* @see [Trailing Slash Configuration](https://nextjs.org/docs/api-reference/next.config.js/trailing-slash)
*/
trailingSlash?: boolean
/**
* Next.js comes with built-in support for environment variables
*
* @see [Environment Variables documentation](https://nextjs.org/docs/api-reference/next.config.js/environment-variables)
*/
env?: Record<string, string>
/**
* Destination directory (defaults to `.next`)
*/
distDir?: string
/**
* The build output directory (defaults to `.next`) is now cleared by default except for the Next.js caches.
*/
cleanDistDir?: boolean
/**
* To set up a CDN, you can set up an asset prefix and configure your CDN's origin to resolve to the domain that Next.js is hosted on.
*
* @see [CDN Support with Asset Prefix](https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix)
*/
assetPrefix?: string
/**
* By default, `Next` will serve each file in the `pages` folder under a pathname matching the filename.
* To disable this behavior and prevent routing based set this to `true`.
*
* @default true
* @see [Disabling file-system routing](https://nextjs.org/docs/advanced-features/custom-server#disabling-file-system-routing)
*/
useFileSystemPublicRoutes?: boolean
/**
* @see [Configuring the build ID](https://nextjs.org/docs/api-reference/next.config.js/configuring-the-build-id)
*/
generateBuildId?: () => string | null | Promise<string | null>
/** @see [Disabling ETag Configuration](https://nextjs.org/docs/api-reference/next.config.js/disabling-etag-generation) */
generateEtags?: boolean
/** @see [Including non-page files in the pages directory](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions) */
pageExtensions?: string[]
/** @see [Compression documentation](https://nextjs.org/docs/api-reference/next.config.js/compression) */
compress?: boolean
/** @see [Disabling x-powered-by](https://nextjs.org/docs/api-reference/next.config.js/disabling-x-powered-by) */
poweredByHeader?: boolean
/** @see [Using the Image Component](https://nextjs.org/docs/basic-features/image-optimization#using-the-image-component) */
images?: ImageConfig
/** Configure indicators in development environment */
devIndicators?: {
/** Show "building..."" indicator in development */
buildActivity?: boolean
/** Position of "building..." indicator in browser */
buildActivityPosition?:
| 'bottom-right'
| 'bottom-left'
| 'top-right'
| 'top-left'
}
/**
* Next.js exposes some options that give you some control over how the server will dispose or keep in memory built pages in development.
*
* @see [Configuring `onDemandEntries`](https://nextjs.org/docs/api-reference/next.config.js/configuring-onDemandEntries)
*/
onDemandEntries?: {
/** period (in ms) where the server will keep pages in the buffer */
maxInactiveAge?: number
/** number of pages that should be kept simultaneously without being disposed */
pagesBufferLength?: number
}
/** @see [`next/amp`](https://nextjs.org/docs/api-reference/next/amp) */
amp?: {
canonicalBase?: string
}
/**
* Deploy a Next.js application under a sub-path of a domain
*
* @see [Base path configuration](https://nextjs.org/docs/api-reference/next.config.js/basepath)
*/
basePath?: string
/** @see [Customizing sass options](https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options) */
sassOptions?: { [key: string]: any }
/**
* Enable browser source map generation during the production build
*
* @see [Source Maps](https://nextjs.org/docs/advanced-features/source-maps)
*/
productionBrowserSourceMaps?: boolean
/**
* By default, Next.js will automatically inline font CSS at build time
*
* @default true
* @since version 10.2
* @see [Font Optimization](https://nextjs.org/docs/basic-features/font-optimization)
*/
optimizeFonts?: boolean
/**
* The Next.js runtime is Strict Mode-compliant.
*
* @see [React Strict Mode](https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode)
*/
reactStrictMode?: boolean
/**
* Add public (in browser) runtime configuration to your app
*
* @see [Runtime configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration)
*/
publicRuntimeConfig?: { [key: string]: any }
/**
* Add server runtime configuration to your app
*
* @see [Runtime configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration)
*/
serverRuntimeConfig?: { [key: string]: any }
/**
* Next.js automatically polyfills node-fetch and enables HTTP Keep-Alive by default.
* You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally.
*
* @see [Disabling HTTP Keep-Alive](https://nextjs.org/docs/api-reference/next.config.js/disabling-http-keep-alive)
*/
httpAgentOptions?: { keepAlive?: boolean }
future?: {
/**
* @deprecated This option has been removed as webpack 5 is now default
*/
webpack5?: false
}
/**
* During a build, Next.js will automatically trace each page and its dependencies to determine all of the files
* that are needed for deploying a production version of your application.
*
* @see [Output File Tracing](https://nextjs.org/docs/advanced-features/output-file-tracing)
*/
outputFileTracing?: boolean
/**
* Timeout after waiting to generate static pages in seconds
*
* @default 60
*/
staticPageGenerationTimeout?: number
/**
* Add `"crossorigin"` attribute to generated `<script>` elements generated by `<Head />` or `<NextScript />` components
*
*
* @see [`crossorigin` attribute documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin)
*/
crossOrigin?: false | 'anonymous' | 'use-credentials'
/**
* Use [SWC compiler](https://swc.rs) to minify the generated JavaScript
*
* @see [SWC Minification](https://nextjs.org/docs/advanced-features/compiler#minification)
*/
swcMinify?: boolean
/**
* Optionally enable compiler transforms
*
* @see [Supported Compiler Options](https://nextjs.org/docs/advanced-features/compiler#supported-features)
*/
compiler?: {
reactRemoveProperties?:
| boolean
| {
properties?: string[]
}
relay?: {
src: string
artifactDirectory?: string
language?: 'typescript' | 'flow'
}
removeConsole?:
| boolean
| {
exclude?: string[]
}
styledComponents?: boolean
}
/**
* Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
*/
experimental?: ExperimentalConfig
}
export const defaultConfig: NextConfig = {
env: {},
webpack: null,
webpackDevMiddleware: null,
eslint: {
ignoreDuringBuilds: false,
},
typescript: {
ignoreBuildErrors: false,
tsconfigPath: 'tsconfig.json',
},
distDir: '.next',
cleanDistDir: true,
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
generateBuildId: () => null,
generateEtags: true,
pageExtensions: ['tsx', 'ts', 'jsx', 'js'],
target: 'server',
poweredByHeader: true,
compress: true,
analyticsId: process.env.VERCEL_ANALYTICS_ID || '',
images: imageConfigDefault,
devIndicators: {
buildActivity: true,
buildActivityPosition: 'bottom-right',
},
onDemandEntries: {
maxInactiveAge: 15 * 1000,
pagesBufferLength: 2,
},
amp: {
canonicalBase: '',
},
basePath: '',
sassOptions: {},
trailingSlash: false,
i18n: null,
productionBrowserSourceMaps: false,
optimizeFonts: true,
webpack5: undefined,
excludeDefaultMomentLocales: true,
serverRuntimeConfig: {},
publicRuntimeConfig: {},
reactStrictMode: false,
httpAgentOptions: {
keepAlive: true,
},
outputFileTracing: true,
staticPageGenerationTimeout: 60,
swcMinify: false,
experimental: {
// TODO: change default in next major release (current v12.1.5)
newNextLinkBehavior: false,
cpus: Math.max(
1,
(Number(process.env.CIRCLE_NODE_TOTAL) ||
(os.cpus() || { length: 1 }).length) - 1
),
sharedPool: true,
plugins: false,
profiling: false,
isrFlushToDisk: true,
workerThreads: false,
pageEnv: false,
optimizeCss: false,
nextScriptWorkers: false,
scrollRestoration: false,
externalDir: false,
reactRoot: Number(process.env.NEXT_PRIVATE_REACT_ROOT) > 0,
disableOptimizedLoading: false,
gzipSize: true,
swcFileReading: true,
craCompat: false,
esmExternals: true,
rootDir: false,
// default to 50MB limit
isrMemoryCacheSize: 50 * 1024 * 1024,
serverComponents: false,
fullySpecified: false,
outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '',
outputStandalone: !!process.env.NEXT_PRIVATE_STANDALONE,
images: {
layoutRaw: false,
remotePatterns: [],
},
},
}
export async function normalizeConfig(phase: string, config: any) {
if (typeof config === 'function') {
config = config(phase, { defaultConfig })
}
// Support `new Promise` and `async () =>` as return values of the config export
return await config
}