-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (36 loc) · 1.14 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
function withSVGComponent(baseConfig = {}) {
return Object.assign({}, baseConfig, {
webpack(config, options) {
config.module.rules = [
...config.module.rules.map(_ => {
if ( _.test && _.test.toString().includes('svg|')) {
return {
..._,
test: new RegExp(_.test.source.replace('svg|', ''))
}
}
return _
}),
{
test: /\.svg$/,
use: [require.resolve('@svgr/webpack'), {
loader: require.resolve('url-loader'),
options: {
limit: baseConfig.inlineImageLimit,
fallback: require.resolve("file-loader"),
publicPath: `${baseConfig.assetPrefix}/_next/static/images/`,
outputPath: `${options.isServer ? "../" : ""}static/images/`,
name: "[name]-[hash].[ext]",
esModule: baseConfig.esModule || false
}
}]
}
]
if (typeof baseConfig.webpack === "function") {
return baseConfig.webpack(config, options);
}
return config;
}
});
};
module.exports = withSVGComponent;