2021-02-27 07:19:35 +01:00
|
|
|
import os from 'os'
|
2022-08-16 11:55:37 +02:00
|
|
|
import type { webpack } from 'next/dist/compiled/webpack/webpack'
|
2022-08-09 21:34:25 +02:00
|
|
|
import type { Header, Redirect, Rewrite } from '../lib/load-custom-routes'
|
2021-09-09 00:03:52 +02:00
|
|
|
import {
|
|
|
|
ImageConfig,
|
|
|
|
ImageConfigComplete,
|
|
|
|
imageConfigDefault,
|
2022-02-22 15:27:18 +01:00
|
|
|
} from '../shared/lib/image-config'
|
2022-08-07 21:16:10 +02:00
|
|
|
import { ServerRuntime } from 'next/types'
|
2022-09-09 00:17:15 +02:00
|
|
|
import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin'
|
add attribution to web vitals (#39368)
This commit implements the main proposal presented in
https://github.com/vercel/next.js/issues/39241
to add attribution to web vitals.
Attribution adds more specific debugging info to web vitals,
for example in the case of Cumulative Layout Shift (CLS),
we might want to know
> What's the first element that shifted when the single largest layout shift occurred?
on in the case of Largest Contentful Paint (LCP),
> What's the element corresponding to the LCP for the page?
> If it is an image, what's the URL of the image resource?
Attribution is *disabled* by default because it could potentially
generate a lot data and overwhelm the RUM backend.
It is enabled *per metric* (LCP, FCP, CLS, etc)
As part of this change, `web-vitals` has been upgraded to v3.0.0
This version contains minor bug fixes, please see changelog at
https://github.com/GoogleChrome/web-vitals/commit/9fe3cc02c875cb70ac0f1803f5e11b428e7a4014
Fixes #39241
## Bug
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
## Feature
- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
## Documentation / Examples
- [ ] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-10-04 02:17:30 +02:00
|
|
|
import { WEB_VITALS } from '../shared/lib/utils'
|
2022-03-26 02:19:51 +01:00
|
|
|
|
2021-09-09 00:03:52 +02:00
|
|
|
export type NextConfigComplete = Required<NextConfig> & {
|
2022-02-09 00:46:59 +01:00
|
|
|
images: Required<ImageConfigComplete>
|
2021-09-24 00:52:05 +02:00
|
|
|
typescript: Required<TypeScriptConfig>
|
2021-10-16 14:22:42 +02:00
|
|
|
configOrigin?: string
|
|
|
|
configFile?: string
|
2021-10-22 01:04:40 +02:00
|
|
|
configFileName: string
|
2021-07-12 23:38:57 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 18:12:33 +02:00
|
|
|
export interface I18NConfig {
|
|
|
|
defaultLocale: string
|
|
|
|
domains?: DomainLocale[]
|
|
|
|
localeDetection?: false
|
|
|
|
locales: string[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface DomainLocale {
|
|
|
|
defaultLocale: string
|
|
|
|
domain: string
|
|
|
|
http?: true
|
|
|
|
locales?: string[]
|
|
|
|
}
|
|
|
|
|
2021-07-23 21:15:26 +02:00
|
|
|
export interface ESLintConfig {
|
2021-07-25 15:48:46 +02:00
|
|
|
/** Only run ESLint on these directories with `next lint` and `next build`. */
|
2021-07-23 21:15:26 +02:00
|
|
|
dirs?: string[]
|
|
|
|
/** Do not run ESLint during production builds (`next build`). */
|
|
|
|
ignoreDuringBuilds?: boolean
|
|
|
|
}
|
|
|
|
|
2021-08-24 16:08:18 +02:00
|
|
|
export interface TypeScriptConfig {
|
|
|
|
/** Do not run TypeScript during production builds (`next build`). */
|
|
|
|
ignoreBuildErrors?: boolean
|
2021-09-24 00:52:05 +02:00
|
|
|
/** Relative path to a custom tsconfig file */
|
|
|
|
tsconfigPath?: string
|
2021-08-24 16:08:18 +02:00
|
|
|
}
|
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
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
|
2022-04-26 23:05:40 +02:00
|
|
|
/** The current server runtime */
|
|
|
|
nextRuntime?: 'nodejs' | 'edge'
|
2022-02-06 02:49:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface NextJsWebpackConfig {
|
|
|
|
(
|
|
|
|
/** Existing Webpack config */
|
|
|
|
config: any,
|
|
|
|
context: WebpackConfigContext
|
|
|
|
): any
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ExperimentalConfig {
|
2022-10-14 21:04:55 +02:00
|
|
|
allowMiddlewareResponseBody?: boolean
|
2022-10-04 19:08:17 +02:00
|
|
|
skipMiddlewareUrlNormalize?: boolean
|
|
|
|
skipTrailingSlashRedirect?: boolean
|
2022-07-26 17:27:39 +02:00
|
|
|
optimisticClientCache?: boolean
|
2022-05-17 17:09:34 +02:00
|
|
|
legacyBrowsers?: boolean
|
2022-05-12 18:47:34 +02:00
|
|
|
manualClientBasePath?: boolean
|
2022-04-26 00:01:30 +02:00
|
|
|
newNextLinkBehavior?: boolean
|
2022-05-28 02:50:21 +02:00
|
|
|
// custom path to a cache handler to use
|
|
|
|
incrementalCacheHandlerPath?: string
|
2022-02-06 02:49:52 +01:00
|
|
|
disablePostcssPresetEnv?: boolean
|
|
|
|
swcMinify?: boolean
|
|
|
|
swcFileReading?: boolean
|
|
|
|
cpus?: number
|
|
|
|
sharedPool?: boolean
|
|
|
|
profiling?: boolean
|
2022-09-07 05:14:08 +02:00
|
|
|
proxyTimeout?: number
|
2022-02-06 02:49:52 +01:00
|
|
|
isrFlushToDisk?: boolean
|
|
|
|
workerThreads?: boolean
|
|
|
|
pageEnv?: boolean
|
2022-07-21 19:53:41 +02:00
|
|
|
// optimizeCss can be boolean or critters' option object
|
|
|
|
// Use Record<string, unknown> as critters doesn't export its Option type
|
|
|
|
// https://github.com/GoogleChromeLabs/critters/blob/a590c05f9197b656d2aeaae9369df2483c26b072/packages/critters/src/index.d.ts
|
|
|
|
optimizeCss?: boolean | Record<string, unknown>
|
2022-03-11 23:26:46 +01:00
|
|
|
nextScriptWorkers?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
scrollRestoration?: boolean
|
|
|
|
externalDir?: boolean
|
2022-05-25 11:46:26 +02:00
|
|
|
appDir?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
amp?: {
|
|
|
|
optimizer?: any
|
|
|
|
validator?: string
|
|
|
|
skipValidation?: boolean
|
|
|
|
}
|
|
|
|
disableOptimizedLoading?: boolean
|
|
|
|
gzipSize?: boolean
|
|
|
|
craCompat?: boolean
|
|
|
|
esmExternals?: boolean | 'loose'
|
|
|
|
isrMemoryCacheSize?: number
|
2022-06-27 03:02:24 +02:00
|
|
|
runtime?: Exclude<ServerRuntime, undefined>
|
2022-02-06 02:49:52 +01:00
|
|
|
fullySpecified?: boolean
|
2022-08-16 11:55:37 +02:00
|
|
|
urlImports?: NonNullable<webpack.Configuration['experiments']>['buildHttp']
|
2022-02-06 02:49:52 +01:00
|
|
|
outputFileTracingRoot?: string
|
2022-03-22 14:20:57 +01:00
|
|
|
modularizeImports?: Record<
|
|
|
|
string,
|
|
|
|
{
|
|
|
|
transform: string
|
|
|
|
preventFullImport?: boolean
|
|
|
|
skipDefaultConversion?: boolean
|
|
|
|
}
|
|
|
|
>
|
2022-05-03 00:20:59 +02:00
|
|
|
swcTraceProfiling?: boolean
|
2022-05-10 12:33:31 +02:00
|
|
|
forceSwcTransforms?: boolean
|
2022-05-29 05:53:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The option for the minifier of [SWC compiler](https://swc.rs).
|
|
|
|
* This option is only for debugging the SWC minifier, and will be removed once the SWC minifier is stable.
|
|
|
|
*
|
|
|
|
* @see [SWC Minification](https://nextjs.org/docs/advanced-features/compiler#minification)
|
|
|
|
*/
|
|
|
|
swcMinifyDebugOptions?: {
|
|
|
|
compress?: object
|
|
|
|
mangle?: object
|
|
|
|
}
|
2022-05-27 00:16:26 +02:00
|
|
|
swcPlugins?: Array<[string, Record<string, unknown>]>
|
2022-05-29 03:39:48 +02:00
|
|
|
largePageDataBytes?: number
|
feat: add `experimental.fallbackNodePolyfills` flag (#39248)
For historical reasons, Next.js has been falling back to polyfill certain Node.js APIs in the browser. `webpack` itself stopped doing it, and so should Next.js. This might unexpectedly break some packages in the ecosystem though, so it is being introduced as an experimental flag. These imports will now throw a `Module not found` error and the package maintainer should make sure that the library isn't relying on these Node.js APIs when the package is meant for browser usage.
Let's take a look at a common example, the `crypto` API, which can be imported as `import crypto from "crypto"` but [should already be available in browsers](https://caniuse.com/cryptography). Until now, Next.js has fallen back to use a polyfilled version for the import, which resulted in a bundle-size increase.
```js
import crypto from 'crypto'
import { useEffect } from 'react'
export default function Page() {
useEffect(() => {
console.log(crypto)
}, [])
}
```
it imports `crypto`, which currently resolves to [`crypto-browserify`](https://www.npmjs.com/package/crypto-browserify).
So the bundle will include `crypto-browserify` as well:
```sh
Page Size First Load JS
┌ ○ / 131 kB 213 kB # <--
└ ○ /404 194 B 82.2 kB
+ First Load JS shared by all 82 kB
├ chunks/framework-bcc2dc0ea27ab0c6.js 45.1 kB
├ chunks/main-dc2421aef72299b4.js 35.4 kB
├ chunks/pages/_app-a85935458980c5c2.js 708 B
└ chunks/webpack-9b312e20a4e32339.js 836 B
```
Here, we can just remove the import, as we are [safely accessing](https://nextjs.org/docs/migrating/from-create-react-app#safely-accessing-web-apis) the [Crypto Web API](https://caniuse.com/cryptography):
```diff
- import crypto from 'crypto'
import { useEffect } from 'react'
export default function Page() {
useEffect(() => {
console.log(crypto)
}, [])
}
```
Which will reduce the bundle size:
```sh
Page Size First Load JS
┌ ○ / 269 B 82.2 kB # <--
└ ○ /404 194 B 82.1 kB
+ First Load JS shared by all 81.9 kB
├ chunks/framework-bcc2dc0ea27ab0c6.js 45.1 kB
├ chunks/main-dc2421aef72299b4.js 35.4 kB
├ chunks/pages/_app-a85935458980c5c2.js 708 B
└ chunks/webpack-fd82975a6094609f.js 727 B
```
This is harder to detect if the `crypto` import is in a third-party package though. By setting `experimental: { fallbackNodePolyfills: false }`, Next.js will now fail at build-time and should show where the unnecessary import comes from, so the developer can reach out to the package maintainer to fix this issue.
Note: There might be differences between the living standard and some of these older polyfills, so you have to make sure your code works well without the polyfilled version.
Related feedback: https://twitter.com/lfredolo/status/1539608666026000384
2022-08-27 01:11:57 +02:00
|
|
|
/**
|
|
|
|
* If set to `false`, webpack won't fall back to polyfill Node.js modules in the browser
|
|
|
|
* Full list of old polyfills is accessible here:
|
|
|
|
* [webpack/webpack#ModuleNotoundError.js#L13-L42](https://github.com/webpack/webpack/blob/2a0536cf510768111a3a6dceeb14cb79b9f59273/lib/ModuleNotFoundError.js#L13-L42)
|
|
|
|
*/
|
|
|
|
fallbackNodePolyfills?: false
|
2022-09-27 22:37:28 +02:00
|
|
|
enableUndici?: boolean
|
2022-09-09 00:17:15 +02:00
|
|
|
sri?: {
|
|
|
|
algorithm?: SubresourceIntegrityAlgorithm
|
|
|
|
}
|
2022-09-16 23:13:21 +02:00
|
|
|
adjustFontFallbacks?: boolean
|
2022-09-30 02:35:50 +02:00
|
|
|
adjustFontFallbacksWithSizeAdjust?: boolean
|
2022-09-24 20:47:42 +02:00
|
|
|
|
|
|
|
// A list of packages that should be treated as external in the RSC server build
|
2022-09-30 15:15:56 +02:00
|
|
|
serverComponentsExternalPackages?: string[]
|
2022-09-24 20:47:42 +02:00
|
|
|
|
2022-10-20 18:49:29 +02:00
|
|
|
// A list of packages that should always be transpiled and bundled in the server
|
|
|
|
transpilePackages?: string[]
|
|
|
|
|
2022-10-22 03:08:37 +02:00
|
|
|
fontLoaders?: Array<{ loader: string; options?: any }>
|
add attribution to web vitals (#39368)
This commit implements the main proposal presented in
https://github.com/vercel/next.js/issues/39241
to add attribution to web vitals.
Attribution adds more specific debugging info to web vitals,
for example in the case of Cumulative Layout Shift (CLS),
we might want to know
> What's the first element that shifted when the single largest layout shift occurred?
on in the case of Largest Contentful Paint (LCP),
> What's the element corresponding to the LCP for the page?
> If it is an image, what's the URL of the image resource?
Attribution is *disabled* by default because it could potentially
generate a lot data and overwhelm the RUM backend.
It is enabled *per metric* (LCP, FCP, CLS, etc)
As part of this change, `web-vitals` has been upgraded to v3.0.0
This version contains minor bug fixes, please see changelog at
https://github.com/GoogleChrome/web-vitals/commit/9fe3cc02c875cb70ac0f1803f5e11b428e7a4014
Fixes #39241
## Bug
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
## Feature
- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
## Documentation / Examples
- [ ] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-10-04 02:17:30 +02:00
|
|
|
|
|
|
|
webVitalsAttribution?: Array<typeof WEB_VITALS[number]>
|
2022-10-25 11:56:26 +02:00
|
|
|
turbotrace?: {
|
|
|
|
logLevel?:
|
|
|
|
| 'bug'
|
|
|
|
| 'fatal'
|
|
|
|
| 'error'
|
|
|
|
| 'warning'
|
|
|
|
| 'hint'
|
|
|
|
| 'note'
|
|
|
|
| 'suggestions'
|
|
|
|
| 'info'
|
|
|
|
logDetail?: boolean
|
2022-10-26 08:31:49 +02:00
|
|
|
logAll?: boolean
|
2022-10-25 11:56:26 +02:00
|
|
|
contextDirectory?: string
|
|
|
|
processCwd?: string
|
2022-10-26 08:31:49 +02:00
|
|
|
maxFiles?: number
|
2022-10-25 11:56:26 +02:00
|
|
|
}
|
2022-11-03 02:24:05 +01:00
|
|
|
mdxRs?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
}
|
|
|
|
|
2022-07-29 19:59:00 +02:00
|
|
|
export type ExportPathMap = {
|
|
|
|
[path: string]: { page: string; query?: Record<string, string | string[]> }
|
|
|
|
}
|
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* Next configuration object
|
|
|
|
* @see [configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/introduction)
|
|
|
|
*/
|
|
|
|
export interface NextConfig extends Record<string, any> {
|
2022-07-29 19:59:00 +02:00
|
|
|
exportPathMap?: (
|
|
|
|
defaultMap: ExportPathMap,
|
|
|
|
ctx: {
|
|
|
|
dev: boolean
|
|
|
|
dir: string
|
|
|
|
outDir: string | null
|
|
|
|
distDir: string
|
|
|
|
buildId: string
|
|
|
|
}
|
|
|
|
) => Promise<ExportPathMap> | ExportPathMap
|
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* Internationalization configuration
|
|
|
|
*
|
|
|
|
* @see [Internationalization docs](https://nextjs.org/docs/advanced-features/i18n-routing)
|
|
|
|
*/
|
2021-07-21 18:12:33 +02:00
|
|
|
i18n?: I18NConfig | null
|
2021-02-27 07:19:35 +01:00
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* @since version 11
|
|
|
|
* @see [ESLint configuration](https://nextjs.org/docs/basic-features/eslint)
|
|
|
|
*/
|
2021-07-23 21:15:26 +02:00
|
|
|
eslint?: ESLintConfig
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see [Next.js TypeScript documentation](https://nextjs.org/docs/basic-features/typescript)
|
|
|
|
*/
|
2021-08-24 16:08:18 +02:00
|
|
|
typescript?: TypeScriptConfig
|
2021-07-23 21:15:26 +02:00
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-02-27 07:19:35 +01:00
|
|
|
headers?: () => Promise<Header[]>
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-03-26 16:19:48 +01:00
|
|
|
rewrites?: () => Promise<
|
|
|
|
| Rewrite[]
|
|
|
|
| {
|
|
|
|
beforeFiles: Rewrite[]
|
|
|
|
afterFiles: Rewrite[]
|
|
|
|
fallback: Rewrite[]
|
|
|
|
}
|
|
|
|
>
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-02-27 07:19:35 +01:00
|
|
|
redirects?: () => Promise<Redirect[]>
|
2021-07-12 23:38:57 +02:00
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* @see [Moment.js locales excluded by default](https://nextjs.org/docs/upgrading#momentjs-locales-excluded-by-default)
|
|
|
|
*/
|
2021-06-14 16:20:34 +02:00
|
|
|
excludeDefaultMomentLocales?: boolean
|
2021-02-27 07:19:35 +01:00
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2021-08-12 17:42:57 +02:00
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
trailingSlash?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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`)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
distDir?: string
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The build output directory (defaults to `.next`) is now cleared by default except for the Next.js caches.
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
cleanDistDir?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
assetPrefix?: string
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
useFileSystemPublicRoutes?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see [Configuring the build ID](https://nextjs.org/docs/api-reference/next.config.js/configuring-the-build-id)
|
|
|
|
*/
|
2021-08-13 00:26:44 +02:00
|
|
|
generateBuildId?: () => string | null | Promise<string | null>
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/** @see [Disabling ETag Configuration](https://nextjs.org/docs/api-reference/next.config.js/disabling-etag-generation) */
|
2021-07-12 23:38:57 +02:00
|
|
|
generateEtags?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/** @see [Including non-page files in the pages directory](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions) */
|
2021-07-12 23:38:57 +02:00
|
|
|
pageExtensions?: string[]
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/** @see [Compression documentation](https://nextjs.org/docs/api-reference/next.config.js/compression) */
|
2021-07-12 23:38:57 +02:00
|
|
|
compress?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
2022-07-22 15:50:24 +02:00
|
|
|
/**
|
|
|
|
* The field should only be used when a Next.js project is not hosted on Vercel while using Vercel Analytics.
|
|
|
|
* Vercel provides zero-configuration analytics for Next.js projects hosted on Vercel.
|
|
|
|
*
|
|
|
|
* @default ''
|
|
|
|
* @see [Next.js Analytics](https://nextjs.org/analytics)
|
|
|
|
*/
|
|
|
|
analyticsId?: string
|
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/** @see [Disabling x-powered-by](https://nextjs.org/docs/api-reference/next.config.js/disabling-x-powered-by) */
|
2021-08-12 17:42:57 +02:00
|
|
|
poweredByHeader?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/** @see [Using the Image Component](https://nextjs.org/docs/basic-features/image-optimization#using-the-image-component) */
|
2021-07-12 23:38:57 +02:00
|
|
|
images?: ImageConfig
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/** Configure indicators in development environment */
|
2021-07-12 23:38:57 +02:00
|
|
|
devIndicators?: {
|
2022-02-06 02:49:52 +01:00
|
|
|
/** Show "building..."" indicator in development */
|
2021-07-12 23:38:57 +02:00
|
|
|
buildActivity?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
/** Position of "building..." indicator in browser */
|
2021-11-03 22:17:36 +01:00
|
|
|
buildActivityPosition?:
|
|
|
|
| 'bottom-right'
|
|
|
|
| 'bottom-left'
|
|
|
|
| 'top-right'
|
|
|
|
| 'top-left'
|
2021-07-12 23:38:57 +02:00
|
|
|
}
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
onDemandEntries?: {
|
2022-02-06 02:49:52 +01:00
|
|
|
/** period (in ms) where the server will keep pages in the buffer */
|
2021-07-12 23:38:57 +02:00
|
|
|
maxInactiveAge?: number
|
2022-02-06 02:49:52 +01:00
|
|
|
/** number of pages that should be kept simultaneously without being disposed */
|
2021-07-12 23:38:57 +02:00
|
|
|
pagesBufferLength?: number
|
|
|
|
}
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/** @see [`next/amp`](https://nextjs.org/docs/api-reference/next/amp) */
|
2021-07-12 23:38:57 +02:00
|
|
|
amp?: {
|
|
|
|
canonicalBase?: string
|
|
|
|
}
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
basePath?: string
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/** @see [Customizing sass options](https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options) */
|
2021-07-12 23:38:57 +02:00
|
|
|
sassOptions?: { [key: string]: any }
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable browser source map generation during the production build
|
|
|
|
*
|
|
|
|
* @see [Source Maps](https://nextjs.org/docs/advanced-features/source-maps)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
productionBrowserSourceMaps?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-07-12 23:38:57 +02:00
|
|
|
optimizeFonts?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Next.js runtime is Strict Mode-compliant.
|
|
|
|
*
|
|
|
|
* @see [React Strict Mode](https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode)
|
|
|
|
*/
|
2022-10-28 02:30:07 +02:00
|
|
|
reactStrictMode?: boolean | null
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add public (in browser) runtime configuration to your app
|
|
|
|
*
|
|
|
|
* @see [Runtime configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration)
|
|
|
|
*/
|
2021-07-20 20:42:29 +02:00
|
|
|
publicRuntimeConfig?: { [key: string]: any }
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add server runtime configuration to your app
|
|
|
|
*
|
|
|
|
* @see [Runtime configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration)
|
|
|
|
*/
|
2021-07-20 20:42:29 +02:00
|
|
|
serverRuntimeConfig?: { [key: string]: any }
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-08-03 02:38:42 +02:00
|
|
|
httpAgentOptions?: { keepAlive?: boolean }
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-10-26 06:22:45 +02:00
|
|
|
outputFileTracing?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Timeout after waiting to generate static pages in seconds
|
|
|
|
*
|
|
|
|
* @default 60
|
|
|
|
*/
|
2021-10-20 21:06:43 +02:00
|
|
|
staticPageGenerationTimeout?: number
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2021-09-21 19:17:16 +02:00
|
|
|
crossOrigin?: false | 'anonymous' | 'use-credentials'
|
2022-02-06 02:49:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use [SWC compiler](https://swc.rs) to minify the generated JavaScript
|
|
|
|
*
|
|
|
|
* @see [SWC Minification](https://nextjs.org/docs/advanced-features/compiler#minification)
|
|
|
|
*/
|
2021-10-25 13:49:11 +02:00
|
|
|
swcMinify?: boolean
|
2022-02-06 02:49:52 +01:00
|
|
|
|
2022-02-10 02:54:28 +01:00
|
|
|
/**
|
|
|
|
* 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[]
|
|
|
|
}
|
2022-06-23 18:55:05 +02:00
|
|
|
styledComponents?:
|
|
|
|
| boolean
|
|
|
|
| {
|
|
|
|
/**
|
|
|
|
* Enabled by default in development, disabled in production to reduce file size,
|
|
|
|
* setting this will override the default for all environments.
|
|
|
|
*/
|
|
|
|
displayName?: boolean
|
|
|
|
topLevelImportPaths?: string[]
|
|
|
|
ssr?: boolean
|
|
|
|
fileName?: boolean
|
|
|
|
meaninglessFileNames?: string[]
|
|
|
|
minify?: boolean
|
|
|
|
transpileTemplateLiterals?: boolean
|
|
|
|
namespace?: string
|
|
|
|
pure?: boolean
|
|
|
|
cssProp?: boolean
|
|
|
|
}
|
2022-05-21 06:09:30 +02:00
|
|
|
emotion?:
|
|
|
|
| boolean
|
|
|
|
| {
|
|
|
|
sourceMap?: boolean
|
|
|
|
autoLabel?: 'dev-only' | 'always' | 'never'
|
|
|
|
labelFormat?: string
|
2022-11-10 22:23:40 +01:00
|
|
|
importMap?: {
|
|
|
|
[importName: string]: {
|
|
|
|
[exportName: string]: {
|
|
|
|
canonicalImport?: [string, string]
|
|
|
|
styledBaseImport?: [string, string]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-21 06:09:30 +02:00
|
|
|
}
|
2022-02-10 02:54:28 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 21:58:35 +02:00
|
|
|
output?: 'standalone'
|
|
|
|
|
2022-02-06 02:49:52 +01:00
|
|
|
/**
|
|
|
|
* Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
|
|
|
|
*/
|
|
|
|
experimental?: ExperimentalConfig
|
2021-02-27 07:19:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const defaultConfig: NextConfig = {
|
2021-07-12 23:38:57 +02:00
|
|
|
env: {},
|
2021-02-27 07:19:35 +01:00
|
|
|
webpack: null,
|
|
|
|
webpackDevMiddleware: null,
|
2021-08-24 16:08:18 +02:00
|
|
|
eslint: {
|
|
|
|
ignoreDuringBuilds: false,
|
|
|
|
},
|
|
|
|
typescript: {
|
|
|
|
ignoreBuildErrors: false,
|
2021-09-24 00:52:05 +02:00
|
|
|
tsconfigPath: 'tsconfig.json',
|
2021-08-24 16:08:18 +02:00
|
|
|
},
|
2021-02-27 07:19:35 +01:00
|
|
|
distDir: '.next',
|
2021-06-14 16:20:34 +02:00
|
|
|
cleanDistDir: true,
|
2021-02-27 07:19:35 +01:00
|
|
|
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,
|
2021-11-03 22:17:36 +01:00
|
|
|
buildActivityPosition: 'bottom-right',
|
2021-02-27 07:19:35 +01:00
|
|
|
},
|
|
|
|
onDemandEntries: {
|
2021-10-11 19:12:16 +02:00
|
|
|
maxInactiveAge: 15 * 1000,
|
2021-02-27 07:19:35 +01:00
|
|
|
pagesBufferLength: 2,
|
|
|
|
},
|
|
|
|
amp: {
|
|
|
|
canonicalBase: '',
|
|
|
|
},
|
|
|
|
basePath: '',
|
|
|
|
sassOptions: {},
|
|
|
|
trailingSlash: false,
|
|
|
|
i18n: null,
|
|
|
|
productionBrowserSourceMaps: false,
|
2021-04-05 19:47:03 +02:00
|
|
|
optimizeFonts: true,
|
2021-07-12 23:38:57 +02:00
|
|
|
excludeDefaultMomentLocales: true,
|
|
|
|
serverRuntimeConfig: {},
|
|
|
|
publicRuntimeConfig: {},
|
2022-10-28 02:30:07 +02:00
|
|
|
reactStrictMode: null,
|
2021-08-03 02:38:42 +02:00
|
|
|
httpAgentOptions: {
|
|
|
|
keepAlive: true,
|
|
|
|
},
|
2021-10-26 06:22:45 +02:00
|
|
|
outputFileTracing: true,
|
2021-10-20 21:06:43 +02:00
|
|
|
staticPageGenerationTimeout: 60,
|
2022-10-18 08:33:04 +02:00
|
|
|
swcMinify: true,
|
2022-06-24 21:58:35 +02:00
|
|
|
output: !!process.env.NEXT_PRIVATE_STANDALONE ? 'standalone' : undefined,
|
2021-02-27 07:19:35 +01:00
|
|
|
experimental: {
|
2022-07-26 17:27:39 +02:00
|
|
|
optimisticClientCache: true,
|
2022-06-28 22:54:45 +02:00
|
|
|
runtime: undefined,
|
2022-06-26 06:05:02 +02:00
|
|
|
manualClientBasePath: false,
|
2022-10-19 03:38:39 +02:00
|
|
|
legacyBrowsers: false,
|
2022-10-18 03:20:28 +02:00
|
|
|
newNextLinkBehavior: true,
|
2021-02-27 07:19:35 +01:00
|
|
|
cpus: Math.max(
|
|
|
|
1,
|
|
|
|
(Number(process.env.CIRCLE_NODE_TOTAL) ||
|
|
|
|
(os.cpus() || { length: 1 }).length) - 1
|
|
|
|
),
|
2021-10-20 21:06:43 +02:00
|
|
|
sharedPool: true,
|
2021-02-27 07:19:35 +01:00
|
|
|
profiling: false,
|
2021-07-22 04:42:33 +02:00
|
|
|
isrFlushToDisk: true,
|
2021-02-27 07:19:35 +01:00
|
|
|
workerThreads: false,
|
|
|
|
pageEnv: false,
|
2022-09-07 05:14:08 +02:00
|
|
|
proxyTimeout: undefined,
|
2021-02-27 07:19:35 +01:00
|
|
|
optimizeCss: false,
|
2022-03-11 23:26:46 +01:00
|
|
|
nextScriptWorkers: false,
|
2021-02-27 07:19:35 +01:00
|
|
|
scrollRestoration: false,
|
2021-03-19 17:43:46 +01:00
|
|
|
externalDir: false,
|
2021-06-12 13:26:47 +02:00
|
|
|
disableOptimizedLoading: false,
|
2021-05-14 16:29:49 +02:00
|
|
|
gzipSize: true,
|
2021-12-02 05:16:15 +01:00
|
|
|
swcFileReading: true,
|
2021-06-09 16:51:56 +02:00
|
|
|
craCompat: false,
|
2021-10-13 23:11:52 +02:00
|
|
|
esmExternals: true,
|
2022-05-25 11:46:26 +02:00
|
|
|
appDir: false,
|
2021-07-21 19:39:38 +02:00
|
|
|
// default to 50MB limit
|
|
|
|
isrMemoryCacheSize: 50 * 1024 * 1024,
|
2022-07-11 18:53:17 +02:00
|
|
|
incrementalCacheHandlerPath: undefined,
|
2021-10-13 17:23:50 +02:00
|
|
|
fullySpecified: false,
|
2021-11-04 10:23:28 +01:00
|
|
|
outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '',
|
2022-06-28 23:20:29 +02:00
|
|
|
swcTraceProfiling: false,
|
2022-05-10 12:33:31 +02:00
|
|
|
forceSwcTransforms: false,
|
2022-06-28 23:20:29 +02:00
|
|
|
swcPlugins: undefined,
|
2022-06-29 12:21:04 +02:00
|
|
|
swcMinifyDebugOptions: undefined,
|
2022-05-29 03:39:48 +02:00
|
|
|
largePageDataBytes: 128 * 1000, // 128KB by default
|
2022-06-29 12:21:04 +02:00
|
|
|
disablePostcssPresetEnv: undefined,
|
|
|
|
amp: undefined,
|
|
|
|
urlImports: undefined,
|
|
|
|
modularizeImports: undefined,
|
2022-09-27 22:37:28 +02:00
|
|
|
enableUndici: false,
|
2022-09-16 23:13:21 +02:00
|
|
|
adjustFontFallbacks: false,
|
2022-09-30 02:35:50 +02:00
|
|
|
adjustFontFallbacksWithSizeAdjust: false,
|
2022-10-25 11:56:26 +02:00
|
|
|
turbotrace: undefined,
|
2021-02-27 07:19:35 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-02-07 09:48:35 +01:00
|
|
|
export async function normalizeConfig(phase: string, config: any) {
|
2021-02-27 07:19:35 +01:00
|
|
|
if (typeof config === 'function') {
|
|
|
|
config = config(phase, { defaultConfig })
|
|
|
|
}
|
2022-02-07 09:48:35 +01:00
|
|
|
// Support `new Promise` and `async () =>` as return values of the config export
|
|
|
|
return await config
|
2021-02-27 07:19:35 +01:00
|
|
|
}
|
2022-07-06 13:06:57 +02:00
|
|
|
|
|
|
|
export function isServerRuntime(value?: string): value is ServerRuntime {
|
|
|
|
return (
|
|
|
|
value === undefined || value === 'nodejs' || value === 'experimental-edge'
|
|
|
|
)
|
|
|
|
}
|
2022-07-13 20:31:55 +02:00
|
|
|
|
|
|
|
export function validateConfig(userConfig: NextConfig): {
|
|
|
|
errors?: Array<any> | null
|
|
|
|
} {
|
|
|
|
const configValidator = require('next/dist/next-config-validate.js')
|
|
|
|
configValidator(userConfig)
|
|
|
|
return {
|
|
|
|
errors: configValidator.errors,
|
|
|
|
}
|
|
|
|
}
|