forked from ensdomains/ens-app-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.mjs
227 lines (210 loc) · 6.24 KB
/
next.config.mjs
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
// @ts-check
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-param-reassign */
import { execSync } from 'child_process'
import path, { dirname } from 'path'
import { fileURLToPath } from 'url'
import { withSentryConfig } from '@sentry/nextjs'
import StylelintPlugin from 'stylelint-webpack-plugin'
const __dirname = dirname(fileURLToPath(import.meta.url))
const babelIncludeRegexes = [
/next[\\/]dist[\\/]shared[\\/]lib/,
/next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/,
/[\\/](strip-ansi|ansi-regex)[\\/]/,
]
/**
* @type {import('next').NextConfig}
* */
const nextConfig = {
reactStrictMode: true,
compiler: {
styledComponents: true,
},
// change to true once infinite loop is fixed
swcMinify: false,
images: {
domains: ['metadata.ens.domains'],
},
async rewrites() {
return [
{
source: '/legacyFavourites',
destination: '/legacyfavourites',
},
{
source: '/my/profile',
destination: '/profile?connected=true',
},
{
source: '/names/:address',
destination: '/my/names?address=:address',
},
{
source: '/:address(0x[a-fA-F0-9]{40}$)',
destination: '/address?address=:address',
},
{
source: '/:name',
destination: '/profile?name=:name',
},
{
source: '/:name/register',
destination: '/register?name=:name',
},
{
source: '/:name/expired-profile',
destination: '/profile?name=:name&expired=true',
},
{
source: '/:name/import',
destination: '/import?name=:name',
},
{
source: '/:name/dotbox',
destination: '/dotbox?name=:name',
},
{
source: '/tld/:tld',
destination: '/profile?name=:tld',
},
{
source: '/tld/:tld/register',
destination: '/register?name=:tld',
},
{
source: '/tld/:tld/expired-profile',
destination: '/profile?name=:tld&expired=true',
},
{
source: '/tld/:tld/import',
destination: '/import?name=:tld',
},
]
},
generateBuildId: () => {
const hash = execSync('git rev-parse HEAD').toString().trim()
return hash
},
webpack: (config, options) => {
for (const rule of config.module.rules) {
if (rule.oneOf && rule.oneOf.length > 5) {
for (const item of rule.oneOf) {
if (typeof item.exclude === 'function' && item.test.toString().includes('js')) {
/**
* @param {string} excludePath
* @returns {boolean}
*/
item.exclude = (excludePath) => {
if (babelIncludeRegexes.some((r) => r.test(excludePath))) {
return false
}
if (/\.yalc\/@ensdomains\/thorin/.test(excludePath)) {
return true
}
if (/\.yalc\/@ensdomains\/ensjs/.test(excludePath)) {
return true
}
return /node_modules/.test(excludePath)
}
}
}
}
}
// Grab the existing rule that handles SVG imports
// @ts-ignore - rules is a private property that is not typed
const fileLoaderRule = config.module.rules.find((rule) => rule.test?.test?.('.svg'))
config.module.rules.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/, // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
use: ['@svgr/webpack'],
},
)
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i
config.resolve.mainFields = ['browser', 'module', 'main']
config.plugins.push(
new StylelintPlugin({
files: './src/**/*.tsx',
extensions: ['tsx'],
failOnError: process.env.NODE_ENV !== 'development',
cache: false,
}),
)
config.plugins.push(
new options.webpack.DefinePlugin({
'process.env.CONFIG_BUILD_ID': JSON.stringify(options.buildId),
}),
)
if (process.env.NEXT_PUBLIC_IPFS) {
config.resolve.alias['../styles.css'] = path.resolve(__dirname, 'src/stub.css')
}
if (!options.isServer && !options.dev) {
const originalEntry = config.entry
/**
* @param {...any} args
*/
config.entry = async (...args) => {
const entryConfig = await originalEntry(...args)
return {
...entryConfig,
firefoxMetamask: {
import: [
'./src/utils/metamask/firefox.ts',
'@metamask/providers',
'@metamask/post-message-stream',
],
filename: 'static/chunks/initialise-metamask.js',
chunkLoading: false,
},
}
}
const originalSplitChunks = config.optimization.splitChunks
config.optimization.splitChunks = {
...originalSplitChunks,
/**
* @param {{ name: string }} chunk
* @returns {boolean}
*/
chunks: (chunk) => !/^(firefoxMetamask|polyfills|main|pages\/_app)$/.test(chunk.name),
}
}
return config
},
eslint: {
// next lint will ignore presets if not stated
dirs: ['src', 'src/components', 'src/pages', 'src/layouts', 'playwright', 'e2e'],
},
...(process.env.NEXT_PUBLIC_IPFS
? {
trailingSlash: true,
assetPrefix: './',
}
: {}),
}
/**
* @type {((config: import('next').NextConfig) => import('next').NextConfig)[]}
*/
const plugins = []
if (process.env.ANALYZE) {
const withBundleAnalyzer = await import('@next/bundle-analyzer').then((n) => n.default)
plugins.push(withBundleAnalyzer({ enabled: true }))
}
if (process.env.CI && process.env.NODE_ENV === 'production' && !process.env.NEXT_PUBLIC_IPFS) {
plugins.push((config) =>
withSentryConfig(config, {
silent: false,
}),
)
}
export default plugins.reduce((acc, next) => next(acc), nextConfig)