/
next.config.js
229 lines (211 loc) · 6.71 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
// @ts-check
/**
* Next.js Configuration
*
* @see https://github.com/cyrilwanner/next-compose-plugins
* @see https://github.com/natterstefan/next-with-sentry/blob/main/next.config.js
*/
const { withSentryConfig } = require('@sentry/nextjs')
const { withPlugins, optional } = require('next-compose-plugins')
const withPreact = require('next-plugin-preact')
const withPWA = require('next-pwa')
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')
const VERCEL = 'VERCEL'
const NETLIFY = 'NETLIFY'
const AMPLIFY = 'AMPLIFY'
const LOCALHOST = 'LOCALHOST'
const detectPlatform = () => {
if (process.env.VERCEL === '1') {
return VERCEL
} else if (process.env.NETLIFY === 'true') {
return NETLIFY
} else if (process.env.CODEBUILD_CI === 'true') {
return AMPLIFY
}
return LOCALHOST // might also be Github CI
}
/* const buildId = `${Date.now()}` */
/* const generateBuildId = async () => buildId */
/**
* @type {import('next/dist/next-server/server/config').NextConfig}
*/
const nextConfiguration = {
amp: {
/* canonicalBase: '', */
},
env: {
NEXT_PUBLIC_SENTRY_DSN:
detectPlatform() === LOCALHOST
? undefined
: 'https://6dbd51aeaa4a4e32b77e9f51a7236a64@o470070.ingest.sentry.io/5842378',
platform: detectPlatform(),
},
eslint: {
/*
* Warning: Dangerously allow production builds to successfully complete even if
* your project has ESLint errors. ... I don't want a production dependency on eslint
*/
ignoreDuringBuilds: true,
},
// @see {@link https://github.com/vercel/next.js/blob/canary/packages/next/next-server/server/config-shared.ts#L68}
/* experimental: { */
// plugins?: boolean;
/* profiling: true, */
/* sprFlushToDisk: true, */
/* workerThreads: false */
/* pageEnv: false */
/* optimizeImages: false, */
/* enableStaticImages: false, */
/* optimizeCss: true, */
/* scrollRestoration: false, */
/* stats: true, */
/* externalDir: false, */
/* reactRoot: Number(process.env.NEXT_PRIVATE_REACT_ROOT) > 0, */
/* enableBlurryPlaceholder: false, */
/* disableOptimizedLoading: true, */
/* gzipSize: true, */
/* }, */
future: {},
// @see {@link https://nextjs.org/docs/api-reference/next.config.js/configuring-the-build-id}
generateBuildId: () => `build-{Date.now()}`,
i18n: {
defaultLocale: 'en',
locales: ['en', 'de', 'es', 'fr', 'it'],
},
/*
* next.js font optimization breaks the link element insofar that there is no 'url' property, which my
* html linter complains about. unfortunately it's not possible to disable the linter because next.js
* puts the updated code at the top of the document head. I should re-enable font-optimization for production
* but will keep it disabled for now to get the linter feedback.
*/
optimizeFonts: false,
poweredByHeader: false,
/*
* publicRuntimeConfig: {
* dns: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN,
* },
*/
reactStrictMode: true,
/* target: 'experimental-serverless-trace', */
webpack: (
/** @type {{ plugins: any[]; }} */ config,
/** @type {{ dev: any; isServer: any; }} */ _options
) =>
/* { buildId, dev, isServer, defaultLoaders, webpack } = options */
config,
}
/**
* Plugins go here
* params: function, configuration?: object, phases?: array
*
* I don't want to have 'bundle-analyzer' loaded in production at all
* so I added this check for an env var
*/
const plugins = () =>
process.env.ANALYZE === 'true'
? [
[
optional(() =>
require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
),
{
/* optional configuration */
},
['!', PHASE_DEVELOPMENT_SERVER],
],
withPreact,
[
withPWA,
{
pwa: {
/* additionalManifestEntries: [ */
/* '/', */
/* '/map', */
/* '/collection', */
/* '/offline', */
/* ].map(url => ({ */
/* revision: buildId, */
/* url, */
/* })), */
dest: 'public',
disable: process.env.NODE_ENV === 'development',
/* dontCacheBustURLsMatching: /^\/_next\/static\/.* /i, */
/* register: false, */
/* skipWaiting: false, */
/* swSrc: 'utils/serviceWorker.ts', */
},
},
],
]
: [
withPreact,
[
withPWA,
{
pwa: {
/* additionalManifestEntries: [ */
/* '/', */
/* '/map', */
/* '/collection', */
/* '/offline', */
/* ].map(url => ({ */
/* revision: buildId, */
/* url, */
/* })), */
dest: 'public',
disable: process.env.NODE_ENV === 'development',
/* dontCacheBustURLsMatching: /^\/_next\/static\/.* /i, */
/* register: false, */
/* skipWaiting: false, */
/* swSrc: 'utils/serviceWorker.ts', */
},
},
],
]
const nextPluginConfiguration = withPlugins(plugins(), nextConfiguration)
/*
* Set a custom webpack configuration to use Next.js app with Sentry.
*
* @see https://nextjs.org/docs/api-reference/next.config.js/introduction
* @see https://docs.sentry.io/platforms/javascript/guides/nextjs/
* @see https://blog.sentry.io/2020/08/04/enable-suspect-commits-unminify-js-and-track-releases-with-vercel-and-sentry
*/
const SentryWebpackPluginOptions = {
/*
* Additional config options for the Sentry Webpack plugin. Keep in mind that
* the following options are set automatically, and overriding them is not
* recommended:
* release, url, org, project, authToken, configFile, stripPrefix,
* urlPrefix, include, ignore
*/
/*
* Modify the event here
* can use this to improve privacy, eg. to disable error reporting if user not d'accord
* @see https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/filtering/
*/
beforeSend(event) {
if (event.user) {
// Don't send user's email address
delete event.user.email
}
return event
},
debug: true,
/* dryRun: process.env.NODE_ENV === 'development', */
dryRun: true,
silent: true, // Suppresses all logs
/*
* For all available options, see:
* https://github.com/getsentry/sentry-webpack-plugin#options.
*/
}
/*
* Make sure adding Sentry options is the last code to run before exporting, to
* ensure that your source maps include changes from all other Webpack plugins
*/
module.exports = withSentryConfig(
nextPluginConfiguration,
SentryWebpackPluginOptions
)