forked from stldo/gatsby-plugin-svg-sprites
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
34 lines (28 loc) · 867 Bytes
/
gatsby-node.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
const SvgSpriteLoaderPlugin = require('svg-sprite-loader/plugin')
exports.onCreateWebpackConfig = (
{ actions, getConfig, rules },
{ pluginOptions = {}, _: plugins, ...options } /* Skip 'plugins' property */
) => {
const config = getConfig()
const imagesTest = String(rules.images().test)
for (let rule of config.module.rules) {
if (String(rule.test) === imagesTest) {
rule.test = new RegExp(imagesTest.replace('svg|', '').slice(1, -1))
}
}
options = {
extract: true,
spriteFilename: 'sprites.[contenthash].svg',
symbolId: '[name]--[hash:base64:5]',
...options
}
config.module.rules.push({
test: /\.svg$/,
loader: require.resolve('svg-sprite-loader'),
options
})
if (options.extract) {
config.plugins.push(new SvgSpriteLoaderPlugin(pluginOptions))
}
actions.replaceWebpackConfig(config)
}