config-shared.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. import type { webpack } from 'next/dist/compiled/webpack/webpack';
  2. import type { Header, Redirect, Rewrite } from '../lib/load-custom-routes';
  3. import { ImageConfig, ImageConfigComplete } from '../shared/lib/image-config';
  4. import { ServerRuntime } from 'next/types';
  5. import { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin';
  6. export declare type NextConfigComplete = Required<NextConfig> & {
  7. images: Required<ImageConfigComplete>;
  8. typescript: Required<TypeScriptConfig>;
  9. configOrigin?: string;
  10. configFile?: string;
  11. configFileName: string;
  12. };
  13. export interface I18NConfig {
  14. defaultLocale: string;
  15. domains?: DomainLocale[];
  16. localeDetection?: false;
  17. locales: string[];
  18. }
  19. export interface DomainLocale {
  20. defaultLocale: string;
  21. domain: string;
  22. http?: true;
  23. locales?: string[];
  24. }
  25. export interface ESLintConfig {
  26. /** Only run ESLint on these directories with `next lint` and `next build`. */
  27. dirs?: string[];
  28. /** Do not run ESLint during production builds (`next build`). */
  29. ignoreDuringBuilds?: boolean;
  30. }
  31. export interface TypeScriptConfig {
  32. /** Do not run TypeScript during production builds (`next build`). */
  33. ignoreBuildErrors?: boolean;
  34. /** Relative path to a custom tsconfig file */
  35. tsconfigPath?: string;
  36. }
  37. export interface WebpackConfigContext {
  38. /** Next.js root directory */
  39. dir: string;
  40. /** Indicates if the compilation will be done in development */
  41. dev: boolean;
  42. /** It's `true` for server-side compilation, and `false` for client-side compilation */
  43. isServer: boolean;
  44. /** The build id, used as a unique identifier between builds */
  45. buildId: string;
  46. /** The next.config.js merged with default values */
  47. config: NextConfigComplete;
  48. /** Default loaders used internally by Next.js */
  49. defaultLoaders: {
  50. /** Default babel-loader configuration */
  51. babel: any;
  52. };
  53. /** Number of total Next.js pages */
  54. totalPages: number;
  55. /** The webpack configuration */
  56. webpack: any;
  57. /** The current server runtime */
  58. nextRuntime?: 'nodejs' | 'edge';
  59. }
  60. export interface NextJsWebpackConfig {
  61. (
  62. /** Existing Webpack config */
  63. config: any, context: WebpackConfigContext): any;
  64. }
  65. export interface ExperimentalConfig {
  66. allowMiddlewareResponseBody?: boolean;
  67. skipMiddlewareUrlNormalize?: boolean;
  68. skipTrailingSlashRedirect?: boolean;
  69. optimisticClientCache?: boolean;
  70. legacyBrowsers?: boolean;
  71. browsersListForSwc?: boolean;
  72. manualClientBasePath?: boolean;
  73. newNextLinkBehavior?: boolean;
  74. incrementalCacheHandlerPath?: string;
  75. disablePostcssPresetEnv?: boolean;
  76. swcMinify?: boolean;
  77. swcFileReading?: boolean;
  78. cpus?: number;
  79. sharedPool?: boolean;
  80. profiling?: boolean;
  81. proxyTimeout?: number;
  82. isrFlushToDisk?: boolean;
  83. workerThreads?: boolean;
  84. pageEnv?: boolean;
  85. optimizeCss?: boolean | Record<string, unknown>;
  86. nextScriptWorkers?: boolean;
  87. scrollRestoration?: boolean;
  88. externalDir?: boolean;
  89. appDir?: boolean;
  90. amp?: {
  91. optimizer?: any;
  92. validator?: string;
  93. skipValidation?: boolean;
  94. };
  95. disableOptimizedLoading?: boolean;
  96. gzipSize?: boolean;
  97. craCompat?: boolean;
  98. esmExternals?: boolean | 'loose';
  99. isrMemoryCacheSize?: number;
  100. runtime?: Exclude<ServerRuntime, undefined>;
  101. serverComponents?: boolean;
  102. fullySpecified?: boolean;
  103. urlImports?: NonNullable<webpack.Configuration['experiments']>['buildHttp'];
  104. outputFileTracingRoot?: string;
  105. modularizeImports?: Record<string, {
  106. transform: string;
  107. preventFullImport?: boolean;
  108. skipDefaultConversion?: boolean;
  109. }>;
  110. swcTraceProfiling?: boolean;
  111. forceSwcTransforms?: boolean;
  112. /**
  113. * The option for the minifier of [SWC compiler](https://swc.rs).
  114. * This option is only for debugging the SWC minifier, and will be removed once the SWC minifier is stable.
  115. *
  116. * @see [SWC Minification](https://nextjs.org/docs/advanced-features/compiler#minification)
  117. */
  118. swcMinifyDebugOptions?: {
  119. compress?: object;
  120. mangle?: object;
  121. };
  122. swcPlugins?: Array<[string, Record<string, unknown>]>;
  123. largePageDataBytes?: number;
  124. /**
  125. * If set to `false`, webpack won't fall back to polyfill Node.js modules in the browser
  126. * Full list of old polyfills is accessible here:
  127. * [webpack/webpack#ModuleNotoundError.js#L13-L42](https://github.com/webpack/webpack/blob/2a0536cf510768111a3a6dceeb14cb79b9f59273/lib/ModuleNotFoundError.js#L13-L42)
  128. */
  129. fallbackNodePolyfills?: false;
  130. sri?: {
  131. algorithm?: SubresourceIntegrityAlgorithm;
  132. };
  133. adjustFontFallbacks?: boolean;
  134. }
  135. export declare type ExportPathMap = {
  136. [path: string]: {
  137. page: string;
  138. query?: Record<string, string | string[]>;
  139. };
  140. };
  141. /**
  142. * Next configuration object
  143. * @see [configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/introduction)
  144. */
  145. export interface NextConfig extends Record<string, any> {
  146. exportPathMap?: (defaultMap: ExportPathMap, ctx: {
  147. dev: boolean;
  148. dir: string;
  149. outDir: string | null;
  150. distDir: string;
  151. buildId: string;
  152. }) => Promise<ExportPathMap> | ExportPathMap;
  153. /**
  154. * Internationalization configuration
  155. *
  156. * @see [Internationalization docs](https://nextjs.org/docs/advanced-features/i18n-routing)
  157. */
  158. i18n?: I18NConfig | null;
  159. /**
  160. * @since version 11
  161. * @see [ESLint configuration](https://nextjs.org/docs/basic-features/eslint)
  162. */
  163. eslint?: ESLintConfig;
  164. /**
  165. * @see [Next.js TypeScript documentation](https://nextjs.org/docs/basic-features/typescript)
  166. */
  167. typescript?: TypeScriptConfig;
  168. /**
  169. * Headers allow you to set custom HTTP headers for an incoming request path.
  170. *
  171. * @see [Headers configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/headers)
  172. */
  173. headers?: () => Promise<Header[]>;
  174. /**
  175. * Rewrites allow you to map an incoming request path to a different destination path.
  176. *
  177. * @see [Rewrites configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/rewrites)
  178. */
  179. rewrites?: () => Promise<Rewrite[] | {
  180. beforeFiles: Rewrite[];
  181. afterFiles: Rewrite[];
  182. fallback: Rewrite[];
  183. }>;
  184. /**
  185. * Redirects allow you to redirect an incoming request path to a different destination path.
  186. *
  187. * @see [Redirects configuration documentation](https://nextjs.org/docs/api-reference/next.config.js/redirects)
  188. */
  189. redirects?: () => Promise<Redirect[]>;
  190. /**
  191. * @deprecated This option has been removed as webpack 5 is now default
  192. * @see [Next.js webpack 5 documentation](https://nextjs.org/docs/messages/webpack5) for upgrading guidance.
  193. */
  194. webpack5?: false;
  195. /**
  196. * @see [Moment.js locales excluded by default](https://nextjs.org/docs/upgrading#momentjs-locales-excluded-by-default)
  197. */
  198. excludeDefaultMomentLocales?: boolean;
  199. /**
  200. * Before continuing to add custom webpack configuration to your application make sure Next.js doesn't already support your use-case
  201. *
  202. * @see [Custom Webpack Config documentation](https://nextjs.org/docs/api-reference/next.config.js/custom-webpack-config)
  203. */
  204. webpack?: NextJsWebpackConfig | null;
  205. /**
  206. * By default Next.js will redirect urls with trailing slashes to their counterpart without a trailing slash.
  207. *
  208. * @default false
  209. * @see [Trailing Slash Configuration](https://nextjs.org/docs/api-reference/next.config.js/trailing-slash)
  210. */
  211. trailingSlash?: boolean;
  212. /**
  213. * Next.js comes with built-in support for environment variables
  214. *
  215. * @see [Environment Variables documentation](https://nextjs.org/docs/api-reference/next.config.js/environment-variables)
  216. */
  217. env?: Record<string, string>;
  218. /**
  219. * Destination directory (defaults to `.next`)
  220. */
  221. distDir?: string;
  222. /**
  223. * The build output directory (defaults to `.next`) is now cleared by default except for the Next.js caches.
  224. */
  225. cleanDistDir?: boolean;
  226. /**
  227. * 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.
  228. *
  229. * @see [CDN Support with Asset Prefix](https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix)
  230. */
  231. assetPrefix?: string;
  232. /**
  233. * By default, `Next` will serve each file in the `pages` folder under a pathname matching the filename.
  234. * To disable this behavior and prevent routing based set this to `true`.
  235. *
  236. * @default true
  237. * @see [Disabling file-system routing](https://nextjs.org/docs/advanced-features/custom-server#disabling-file-system-routing)
  238. */
  239. useFileSystemPublicRoutes?: boolean;
  240. /**
  241. * @see [Configuring the build ID](https://nextjs.org/docs/api-reference/next.config.js/configuring-the-build-id)
  242. */
  243. generateBuildId?: () => string | null | Promise<string | null>;
  244. /** @see [Disabling ETag Configuration](https://nextjs.org/docs/api-reference/next.config.js/disabling-etag-generation) */
  245. generateEtags?: boolean;
  246. /** @see [Including non-page files in the pages directory](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions) */
  247. pageExtensions?: string[];
  248. /** @see [Compression documentation](https://nextjs.org/docs/api-reference/next.config.js/compression) */
  249. compress?: boolean;
  250. /**
  251. * The field should only be used when a Next.js project is not hosted on Vercel while using Vercel Analytics.
  252. * Vercel provides zero-configuration analytics for Next.js projects hosted on Vercel.
  253. *
  254. * @default ''
  255. * @see [Next.js Analytics](https://nextjs.org/analytics)
  256. */
  257. analyticsId?: string;
  258. /** @see [Disabling x-powered-by](https://nextjs.org/docs/api-reference/next.config.js/disabling-x-powered-by) */
  259. poweredByHeader?: boolean;
  260. /** @see [Using the Image Component](https://nextjs.org/docs/basic-features/image-optimization#using-the-image-component) */
  261. images?: ImageConfig;
  262. /** Configure indicators in development environment */
  263. devIndicators?: {
  264. /** Show "building..."" indicator in development */
  265. buildActivity?: boolean;
  266. /** Position of "building..." indicator in browser */
  267. buildActivityPosition?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
  268. };
  269. /**
  270. * Next.js exposes some options that give you some control over how the server will dispose or keep in memory built pages in development.
  271. *
  272. * @see [Configuring `onDemandEntries`](https://nextjs.org/docs/api-reference/next.config.js/configuring-onDemandEntries)
  273. */
  274. onDemandEntries?: {
  275. /** period (in ms) where the server will keep pages in the buffer */
  276. maxInactiveAge?: number;
  277. /** number of pages that should be kept simultaneously without being disposed */
  278. pagesBufferLength?: number;
  279. };
  280. /** @see [`next/amp`](https://nextjs.org/docs/api-reference/next/amp) */
  281. amp?: {
  282. canonicalBase?: string;
  283. };
  284. /**
  285. * Deploy a Next.js application under a sub-path of a domain
  286. *
  287. * @see [Base path configuration](https://nextjs.org/docs/api-reference/next.config.js/basepath)
  288. */
  289. basePath?: string;
  290. /** @see [Customizing sass options](https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options) */
  291. sassOptions?: {
  292. [key: string]: any;
  293. };
  294. /**
  295. * Enable browser source map generation during the production build
  296. *
  297. * @see [Source Maps](https://nextjs.org/docs/advanced-features/source-maps)
  298. */
  299. productionBrowserSourceMaps?: boolean;
  300. /**
  301. * By default, Next.js will automatically inline font CSS at build time
  302. *
  303. * @default true
  304. * @since version 10.2
  305. * @see [Font Optimization](https://nextjs.org/docs/basic-features/font-optimization)
  306. */
  307. optimizeFonts?: boolean;
  308. /**
  309. * The Next.js runtime is Strict Mode-compliant.
  310. *
  311. * @see [React Strict Mode](https://nextjs.org/docs/api-reference/next.config.js/react-strict-mode)
  312. */
  313. reactStrictMode?: boolean;
  314. /**
  315. * Add public (in browser) runtime configuration to your app
  316. *
  317. * @see [Runtime configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration)
  318. */
  319. publicRuntimeConfig?: {
  320. [key: string]: any;
  321. };
  322. /**
  323. * Add server runtime configuration to your app
  324. *
  325. * @see [Runtime configuration](https://nextjs.org/docs/api-reference/next.config.js/runtime-configuration)
  326. */
  327. serverRuntimeConfig?: {
  328. [key: string]: any;
  329. };
  330. /**
  331. * Next.js automatically polyfills node-fetch and enables HTTP Keep-Alive by default.
  332. * You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally.
  333. *
  334. * @see [Disabling HTTP Keep-Alive](https://nextjs.org/docs/api-reference/next.config.js/disabling-http-keep-alive)
  335. */
  336. httpAgentOptions?: {
  337. keepAlive?: boolean;
  338. };
  339. future?: {
  340. /**
  341. * @deprecated This option has been removed as webpack 5 is now default
  342. */
  343. webpack5?: false;
  344. };
  345. /**
  346. * During a build, Next.js will automatically trace each page and its dependencies to determine all of the files
  347. * that are needed for deploying a production version of your application.
  348. *
  349. * @see [Output File Tracing](https://nextjs.org/docs/advanced-features/output-file-tracing)
  350. */
  351. outputFileTracing?: boolean;
  352. /**
  353. * Timeout after waiting to generate static pages in seconds
  354. *
  355. * @default 60
  356. */
  357. staticPageGenerationTimeout?: number;
  358. /**
  359. * Add `"crossorigin"` attribute to generated `<script>` elements generated by `<Head />` or `<NextScript />` components
  360. *
  361. *
  362. * @see [`crossorigin` attribute documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin)
  363. */
  364. crossOrigin?: false | 'anonymous' | 'use-credentials';
  365. /**
  366. * Use [SWC compiler](https://swc.rs) to minify the generated JavaScript
  367. *
  368. * @see [SWC Minification](https://nextjs.org/docs/advanced-features/compiler#minification)
  369. */
  370. swcMinify?: boolean;
  371. /**
  372. * Optionally enable compiler transforms
  373. *
  374. * @see [Supported Compiler Options](https://nextjs.org/docs/advanced-features/compiler#supported-features)
  375. */
  376. compiler?: {
  377. reactRemoveProperties?: boolean | {
  378. properties?: string[];
  379. };
  380. relay?: {
  381. src: string;
  382. artifactDirectory?: string;
  383. language?: 'typescript' | 'flow';
  384. };
  385. removeConsole?: boolean | {
  386. exclude?: string[];
  387. };
  388. styledComponents?: boolean | {
  389. /**
  390. * Enabled by default in development, disabled in production to reduce file size,
  391. * setting this will override the default for all environments.
  392. */
  393. displayName?: boolean;
  394. topLevelImportPaths?: string[];
  395. ssr?: boolean;
  396. fileName?: boolean;
  397. meaninglessFileNames?: string[];
  398. minify?: boolean;
  399. transpileTemplateLiterals?: boolean;
  400. namespace?: string;
  401. pure?: boolean;
  402. cssProp?: boolean;
  403. };
  404. emotion?: boolean | {
  405. sourceMap?: boolean;
  406. autoLabel?: 'dev-only' | 'always' | 'never';
  407. labelFormat?: string;
  408. };
  409. };
  410. output?: 'standalone';
  411. /**
  412. * Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
  413. */
  414. experimental?: ExperimentalConfig;
  415. }
  416. export declare const defaultConfig: NextConfig;
  417. export declare function normalizeConfig(phase: string, config: any): Promise<any>;
  418. export declare function isServerRuntime(value?: string): value is ServerRuntime;
  419. export declare function validateConfig(userConfig: NextConfig): {
  420. errors?: Array<any> | null;
  421. };