-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
44 lines (38 loc) · 1.16 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
module.exports = (nextConfig = {}) => {
const svgrNextConfig = {
...nextConfig,
webpack(config, options) {
const { isServer } = options;
const { svgrOptions, fileLoader, assetPrefix } = nextConfig;
const use = [
{
loader: require.resolve('@svgr/webpack'),
options: svgrOptions || {},
},
];
if (fileLoader) {
const path = 'static/media/';
const defaultOptions = {
limit: 8192,
publicPath: `${assetPrefix ?? ''}/_next/${path}`,
outputPath: `${isServer ? '../' : ''}${path}`,
name: '[path][name].[hash].[ext]',
};
const options =
typeof fileLoader === 'boolean' ? defaultOptions : { ...defaultOptions, ...fileLoader };
use.push({ loader: require.resolve('file-loader'), options });
}
config.module.rules.push({
test: /\.svg$/,
use,
});
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options);
}
return config;
},
};
delete svgrNextConfig.fileLoader;
delete svgrNextConfig.svgrOptions;
return svgrNextConfig;
};