/
config-shared.ts
377 lines (355 loc) · 11.4 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
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,
} from './image-config'
export type NextConfigComplete = Required<NextConfig> & {
images: 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
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
}
export interface NextJsWebpackConfig {
(
/** Existing Webpack config */
config: any,
context: WebpackConfigContext
): any
}
export type NextConfig = { [key: string]: any } & {
i18n?: I18NConfig | null
eslint?: ESLintConfig
typescript?: TypeScriptConfig
/**
* Headers allow you to set custom HTTP headers for an incoming request path.
*
* Refer to complete [Headers configuration documentations](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.
*
* Rewrites act as a URL proxy and mask the destination path, making it appear the user hasn't changed their location on the site.
* In contrast, redirects will reroute to a new page and show the URL changes
*
* Refer to complete [Rewrites configuration documentations](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.
*
* Redirects are only available on the Node.js environment and do not affect client-side routing.
*
* Refer to complete [Redirects configuration documentations](https://nextjs.org/docs/api-reference/next.config.js/redirects)
*/
redirects?: () => Promise<Redirect[]>
/**
* Webpack 5 is now the default for all Next.js applications. If you did not have custom webpack configuration your application is already using webpack 5.
* If you do have custom webpack configuration you can refer to the [Next.js webpack 5 documentation](https://nextjs.org/docs/messages/webpack5) for upgrading guidance.
*/
webpack5?: false
/**
* Moment.js includes translations for a lot of locales by default. Next.js now automatically excludes these locales by default
* to optimize bundle size for applications using Moment.js.
*
* To load a specific locale use this snippet:
*
* ```js
* import moment from 'moment'
* import 'moment/locale/ja'
*
* moment.locale('ja')
* ```
*
* You can opt-out of this new default by adding `excludeDefaultMomentLocales: false` to `next.config.js` if you do not want the new behavior,
* do note it's highly recommended to not disable this new optimization as it significantly reduces the size of Moment.js.
*/
excludeDefaultMomentLocales?: boolean
/**
* Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case
*
* Refer to complete [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.
* For example /about/ will redirect to /about. You can configure this behavior to act the opposite way,
* where urls without trailing slashes are redirected to their counterparts with trailing slashes.
*
* Refer to complete [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, which allows you to do the following:
*
* - [Use `.env.local` to load environment variables](#loading-environment-variables)
* - [Expose environment variables to the browser by prefixing with `NEXT_PUBLIC_`](#exposing-environment-variables-to-the-browser)
*
* Refer to complete [Environment Variables documentation](https://nextjs.org/docs/api-reference/next.config.js/environment-variables)
*/
env?: { [key: string]: string }
/**
* Detonation directory
*/
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.
* If your project uses a custom server, this behavior may result in the same content being served from multiple paths,
* which can present problems with SEO and UX.
*
* To disable this behavior set this option to `false`.
*/
useFileSystemPublicRoutes?: boolean
/**
* Next.js uses a constant id generated at build time to identify which version of your application is being served.
* This can cause problems in multi-server deployments when `next build` is ran on every server.
* In order to keep a static build id between builds you can provide your own build id.
*
* Use this option to provide your own build id.
*/
generateBuildId?: () => string | null | Promise<string | null>
generateEtags?: boolean
pageExtensions?: string[]
compress?: boolean
poweredByHeader?: boolean
images?: ImageConfig
devIndicators?: {
buildActivity?: boolean
buildActivityPosition?:
| 'bottom-right'
| 'bottom-left'
| 'top-right'
| 'top-left'
}
onDemandEntries?: {
maxInactiveAge?: number
pagesBufferLength?: number
}
amp?: {
canonicalBase?: string
}
basePath?: string
sassOptions?: { [key: string]: any }
productionBrowserSourceMaps?: boolean
optimizeFonts?: boolean
reactStrictMode?: boolean
publicRuntimeConfig?: { [key: string]: any }
serverRuntimeConfig?: { [key: string]: any }
httpAgentOptions?: { keepAlive?: boolean }
future?: {
/**
* @deprecated this options was moved to the top level
*/
webpack5?: false
}
outputFileTracing?: boolean
staticPageGenerationTimeout?: number
crossOrigin?: false | 'anonymous' | 'use-credentials'
swcMinify?: boolean
experimental?: {
disablePostcssPresetEnv?: boolean
removeConsole?:
| boolean
| {
exclude?: string[]
}
reactRemoveProperties?:
| boolean
| {
properties?: string[]
}
styledComponents?: boolean
swcMinify?: boolean
swcFileReading?: boolean
cpus?: number
sharedPool?: boolean
plugins?: boolean
profiling?: boolean
isrFlushToDisk?: boolean
reactMode?: 'legacy' | 'concurrent' | 'blocking'
workerThreads?: boolean
pageEnv?: boolean
optimizeImages?: boolean
optimizeCss?: boolean
scrollRestoration?: boolean
externalDir?: boolean
conformance?: boolean
amp?: {
optimizer?: any
validator?: string
skipValidation?: boolean
}
reactRoot?: boolean
disableOptimizedLoading?: boolean
gzipSize?: boolean
craCompat?: boolean
esmExternals?: boolean | 'loose'
isrMemoryCacheSize?: number
concurrentFeatures?: boolean
serverComponents?: boolean
fullySpecified?: boolean
urlImports?: NonNullable<webpack5.Configuration['experiments']>['buildHttp']
outputFileTracingRoot?: string
outputStandalone?: boolean
}
}
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: {
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,
optimizeImages: false,
optimizeCss: false,
scrollRestoration: false,
externalDir: false,
reactRoot: Number(process.env.NEXT_PRIVATE_REACT_ROOT) > 0,
disableOptimizedLoading: false,
gzipSize: true,
swcFileReading: true,
craCompat: false,
esmExternals: true,
// default to 50MB limit
isrMemoryCacheSize: 50 * 1024 * 1024,
concurrentFeatures: false,
serverComponents: false,
fullySpecified: false,
outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '',
outputStandalone: !!process.env.NEXT_PRIVATE_STANDALONE,
},
}
export function normalizeConfig(phase: string, config: any) {
if (typeof config === 'function') {
config = config(phase, { defaultConfig })
if (typeof config.then === 'function') {
throw new Error(
'> Promise returned in next config. https://nextjs.org/docs/messages/promise-in-next-config'
)
}
}
return config
}