-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
executable file
·202 lines (193 loc) · 5.31 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
// @ts-check
const { i18n } = require('./next-i18next.config')
const { withPlugins } = require('next-compose-plugins')
const path = require('path')
const StylelintPlugin = require('stylelint-webpack-plugin')
// const { withSentryConfig } = require('@sentry/nextjs')
const { execSync } = require('child_process')
const babelIncludeRegexes = [
/next[\\/]dist[\\/]shared[\\/]lib/,
/next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/,
/[\\/](strip-ansi|ansi-regex)[\\/]/,
]
/**
* @type {import('next').NextConfig}
**/
let nextConfig = {
reactStrictMode: true,
typescript: {
ignoreBuildErrors: true
},
compiler: {
styledComponents: true,
},
experimental: {
// remove this once this PR is merged to main: https://github.com/vercel/next.js/pull/33236
swcFileReading: false,
},
// change to true once infinite loop is fixed
swcMinify: false,
// @ts-ignore
images: {
domains: ['metadata.ens.domains'],
},
async rewrites() {
return [
{
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: '/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')) {
item.exclude = (excludePath) => {
if (babelIncludeRegexes.some((r) => r.test(excludePath))) {
return false
}
if (/\.yalc\/@ensdomains\/thorin/.test(excludePath)) {
return true
}
return /node_modules/.test(excludePath)
}
}
}
}
}
// config.module.rules.push({
// // test for .js or .mjs
// test: /(?<!@ethersproject\/.*)\.m?js$/,
// use: {
// loader: path.resolve(__dirname, './loaders/ethers-loader.js'),
// options: {},
// },
// })
config.module.rules.push({
test: /ens.+\.json$/,
use: {
loader: path.resolve(__dirname, './loaders/abi-loader.js'),
options: {},
},
})
config.module.rules.push({
test: /\.svg$/,
issuer: /\.tsx?$/,
include: [options.dir],
use: [
'next-swc-loader',
{
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: [
{
name: 'removeViewBox',
active: false,
},
],
},
babel: false,
},
},
],
})
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')
}
config.resolve.alias['@ethersproject/strings/lib/idna.js'] = path.resolve(
__dirname,
'src/stub.js',
)
return config
},
...(process.env.NEXT_PUBLIC_IPFS
? {
trailingSlash: true,
assetPrefix: './',
}
: {}),
}
let plugins = []
if (process.env.ANALYZE) {
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: true,
})
plugins.push([withBundleAnalyzer])
}
const withSentry = (config) => {
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
silent: false, // Suppresses all logs
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options.
}
// if (process.env.NODE_ENV === 'production' && !process.env.NEXT_PUBLIC_IPFS)
// return withSentryConfig(config, sentryWebpackPluginOptions)
return config
}
module.exports = withPlugins(plugins, nextConfig)