-
Notifications
You must be signed in to change notification settings - Fork 16
/
next.config.js
232 lines (205 loc) · 6.03 KB
/
next.config.js
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
// @ts-check
const pc = require('picocolors');
const packageJson = require('./package.json');
const trueEnv = ['true', '1', 'yes'];
const isProd = process.env.NODE_ENV === 'production';
const NEXTJS_IGNORE_ESLINT = trueEnv.includes(
process.env?.NEXTJS_IGNORE_ESLINT ?? 'false'
);
const NEXTJS_IGNORE_TYPECHECK = trueEnv.includes(
process.env?.NEXTJS_IGNORE_TYPECHECK ?? 'false'
);
/**
* A way to allow CI optimization when the build done there is not used
* to deliver an image or deploy the files.
* @link https://nextjs.org/docs/advanced-features/source-maps
*/
const disableSourceMaps = trueEnv.includes(
process.env?.NEXT_DISABLE_SOURCEMAPS ?? 'false'
);
if (disableSourceMaps) {
console.warn(
`${pc.yellow(
'notice'
)}- Sourcemaps generation have been disabled through NEXT_DISABLE_SOURCEMAPS`
);
}
// Tell webpack to compile those packages
// @link https://www.npmjs.com/package/next-transpile-modules
const tmModules = [
// for legacy browsers support (only in prod)
...(isProd
? [
// ie: '@react-google-maps/api'...
]
: []),
// ESM only packages are not yet supported by NextJs if you're not
// using experimental experimental esmExternals
// @link {https://nextjs.org/blog/next-11-1#es-modules-support|Blog 11.1.0}
// @link {https://github.com/vercel/next.js/discussions/27876|Discussion}
// @link https://github.com/vercel/next.js/issues/23725
// @link https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
...[
// ie: newer versions of https://github.com/sindresorhus packages
],
];
if (disableSourceMaps) {
console.info(
`${pc.green(
'notice'
)}- Sourcemaps generation have been disabled through NEXT_DISABLE_SOURCEMAPS`
);
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
reactStrictMode: false,
productionBrowserSourceMaps: !disableSourceMaps,
optimizeFonts: true,
httpAgentOptions: {
// @link https://nextjs.org/blog/next-11-1#builds--data-fetching
keepAlive: true,
},
// @link https://nextjs.org/docs/advanced-features/compiler#minification
swcMinify: true,
compiler: {
// @https://nextjs.org/docs/advanced-features/compiler#remove-react-properties
// Rust regexes, the syntax is different from js, see https://docs.rs/regex.
reactRemoveProperties: { properties: ['^data-test$'] },
removeConsole: {
exclude: ['error', 'log'],
},
},
experimental: {
browsersListForSwc: true,
legacyBrowsers: false,
// React 18 server components
// @link https://nextjs.org/docs/advanced-features/react-18/server-components
serverComponents: false,
// @link https://nextjs.org/docs/advanced-features/output-file-tracing#caveats
outputFileTracingRoot: undefined, // ,path.join(__dirname, '../../'),
// Prefer loading of ES Modules over CommonJS
// @link {https://nextjs.org/blog/next-11-1#es-modules-support|Blog 11.1.0}
// @link {https://github.com/vercel/next.js/discussions/27876|Discussion}
esmExternals: true,
// Experimental monorepo support
// @link {https://github.com/vercel/next.js/pull/22867|Original PR}
// @link {https://github.com/vercel/next.js/discussions/26420|Discussion}
externalDir: true,
},
typescript: {
ignoreBuildErrors: NEXTJS_IGNORE_TYPECHECK,
tsconfigPath: './tsconfig.json',
},
eslint: {
ignoreDuringBuilds: NEXTJS_IGNORE_ESLINT,
dirs: ['src'],
},
async headers() {
return [];
},
/**
* @link https://nextjs.org/docs/api-reference/next.config.js/rewrites
async rewrites() {
return [
{
source: `/hello`,
destination: '/hello-world',
},
];
},
*/
// @link https://nextjs.org/docs/basic-features/image-optimization
images: {
loader: 'default',
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
disableStaticImages: false,
// https://nextjs.org/docs/api-reference/next/image#caching-behavior
minimumCacheTTL: 60,
// Allowed domains for next/image
domains: [
'd23fdhqc1jb9no.cloudfront.net',
'realms-assets.s3.eu-west-3.amazonaws.com',
],
remotePatterns: [
{
protocol: 'https',
hostname: 'avatars.githubusercontent.com',
},
{
protocol: 'https',
hostname: 'ingave-images.s3.eu-west-3.amazonaws.com',
},
],
unoptimized: false,
},
webpack: (config, { webpack, isServer }) => {
if (!isServer) {
config.resolve.fallback = { ...config.resolve.fallback, fs: false };
}
config.module.rules.push(
{
test: /\.(glb|gltf)$/,
use: {
loader: 'file-loader',
},
},
{
test: /\.svg$/,
issuer: /\.(js|ts)x?$/,
use: [
{
loader: '@svgr/webpack',
// https://react-svgr.com/docs/webpack/#passing-options
options: {
svgo: true,
// @link https://github.com/svg/svgo#configuration
svgoConfig: {
multipass: false,
datauri: 'base64',
js2svg: {
indent: 2,
pretty: false,
},
},
},
},
],
}
);
return config;
},
env: {
APP_NAME: packageJson.name,
APP_VERSION: packageJson.version,
BUILD_TIME: new Date().toISOString(),
},
serverRuntimeConfig: {
// to bypass https://github.com/zeit/next.js/issues/8251
PROJECT_ROOT: __dirname,
},
};
let config = nextConfig;
if (tmModules.length > 0) {
console.info(
`${pc.green('notice')}- Will transpile [${tmModules.join(',')}]`
);
const withNextTranspileModules = require('next-transpile-modules')(
tmModules,
{
resolveSymlinks: true,
debug: false,
}
);
config = withNextTranspileModules(config);
}
if (process.env.ANALYZE === 'true') {
// @ts-ignore
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: true,
});
config = withBundleAnalyzer(config);
}
module.exports = config;