-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathindex.js
69 lines (64 loc) · 2.41 KB
/
index.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
module.exports = ({ dynamicAssetPrefix = false, ...nextConfig } = {}) => {
return Object.assign({}, nextConfig, {
serverRuntimeConfig: dynamicAssetPrefix
? Object.assign({}, nextConfig.serverRuntimeConfig, {
nextImagesAssetPrefix: nextConfig.assetPrefix || nextConfig.basePath,
})
: nextConfig.serverRuntimeConfig,
webpack(config, options) {
const { isServer } = options;
nextConfig = Object.assign({
inlineImageLimit: 8192,
assetPrefix: "",
basePath: "",
fileExtensions: ["jpg", "jpeg", "png", "svg", "gif", "ico", "webp", "jp2", "avif"],
}, nextConfig);
if (!options.defaultLoaders) {
throw new Error(
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
)
}
config.module.rules.push({
test: new RegExp(`\\.(${nextConfig.fileExtensions.join('|')})$`),
// Next.js already handles url() in css/sass/scss files
issuer: new RegExp('\\.\\w+(?<!(s?c|sa)ss)$', 'i'),
exclude: nextConfig.exclude,
use: [
{
loader: require.resolve("url-loader"),
options: {
limit: nextConfig.inlineImageLimit,
fallback: require.resolve("file-loader"),
outputPath: `${isServer ? "../" : ""}static/images/`,
...(dynamicAssetPrefix
? {
publicPath: `${
isServer ? '/_next/' : ''
}static/images/`,
postTransformPublicPath: (p) => {
if (isServer) {
return `(require("next/config").default().serverRuntimeConfig.nextImagesAssetPrefix || '') + ${p}`;
}
return `(__webpack_public_path__ || '') + ${p}`;
},
}
: {
publicPath: `${
nextConfig.assetPrefix ||
nextConfig.basePath ||
''
}/_next/static/images/`,
}),
name: nextConfig.name || "[name]-[hash].[ext]",
esModule: nextConfig.esModule || false
}
}
]
});
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
}
})
}