-
Notifications
You must be signed in to change notification settings - Fork 34
/
next.config.js
57 lines (53 loc) · 1.47 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
const { createLoader } = require('simple-functional-loader')
module.exports = {
experimental: {
modern: true,
polyfillsOptimization: true,
},
webpack(config, options) {
config.module.rules.push({
test: /\.svg$/i,
use: [
options.defaultLoaders.babel,
createLoader(function (code) {
return code.replace(/"(.*?)(?<!\\)"/gs, (_, svg) =>
svg
.replace(/>(\s|\\n)+</g, '><')
.replace(/\\n$/, '')
.replace(/\\"/g, '"')
.replace(
/(\s)([a-z-]+)="([^"]+)"/gi,
(_, prefix, attr, value) => {
const jsxValue = /^[0-9.]+$/.test(value)
? `{${value}}`
: `"${value}"`
return `${prefix}${attr.replace(
/-([a-z])/gi,
(_, letter) => `${letter.toUpperCase()}`
)}=${jsxValue}`
}
)
.replace(
/<svg[^>]+>(.*?)<\/svg>/s,
(svg.match(/</g) || []).length > 3 ? '(<>$1</>)' : '($1)'
)
)
}),
'raw-loader',
],
})
config.module.rules.push({
test: /\.(png|jpe?g|gif|webp)$/i,
use: [
{
loader: 'file-loader',
options: {
publicPath: '/_next',
name: 'static/media/[name].[hash].[ext]',
},
},
],
})
return config
},
}