/
types.ts
80 lines (66 loc) · 2.37 KB
/
types.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
import { SentryCliPluginOptions } from '@sentry/webpack-plugin';
export type SentryWebpackPluginOptions = SentryCliPluginOptions;
export type SentryWebpackPlugin = { options: SentryWebpackPluginOptions };
/**
* Overall Nextjs config
*/
export type ExportedNextConfig = NextConfigObject | NextConfigFunction;
export type NextConfigObject = {
// custom webpack options
webpack?: WebpackConfigFunction;
// whether to build serverless functions for all pages, not just API routes
target?: 'server' | 'experimental-serverless-trace';
sentry?: {
disableServerWebpackPlugin?: boolean;
disableClientWebpackPlugin?: boolean;
};
} & {
// other `next.config.js` options
[key: string]: unknown;
};
export type NextConfigFunction = (
phase: string,
defaults: { defaultConfig: { [key: string]: unknown } },
) => NextConfigObject;
/**
* Webpack config
*/
// the format for providing custom webpack config in your nextjs options
export type WebpackConfigFunction = (config: WebpackConfigObject, options: BuildContext) => WebpackConfigObject;
export type WebpackConfigObject = {
devtool?: string;
plugins?: Array<{ [key: string]: unknown }>;
entry: WebpackEntryProperty;
output: { filename: string; path: string };
target: string;
context: string;
resolve?: {
alias?: { [key: string]: string | boolean };
};
} & {
// other webpack options
[key: string]: unknown;
};
// Information about the current build environment
export type BuildContext = {
dev: boolean;
isServer: boolean;
buildId: string;
dir: string;
config: Partial<NextConfigObject>;
webpack: { version: string };
};
/**
* Webpack `entry` config
*/
// For our purposes, the value for `entry` is either an object, or an async function which returns such an object
export type WebpackEntryProperty = EntryPropertyObject | EntryPropertyFunction;
export type EntryPropertyObject = {
[key: string]: EntryPointValue;
};
export type EntryPropertyFunction = () => Promise<EntryPropertyObject>;
// Each value in that object is either a string representing a single entry point, an array of such strings, or an
// object containing either of those, along with other configuration options. In that third case, the entry point(s) are
// listed under the key `import`.
export type EntryPointValue = string | Array<string> | EntryPointObject;
export type EntryPointObject = { import: string | Array<string> };