Skip to content

Commit 09f31ee

Browse files
authored
Update the SVG sprite creation to use SVGO v2 (#591)
1 parent 9b158b5 commit 09f31ee

File tree

4 files changed

+409
-494
lines changed

4 files changed

+409
-494
lines changed

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-mpa-next",
3-
"version": "3.7.1",
3+
"version": "3.8.0",
44
"description": "Multi page app setup with webpack",
55
"scripts": {
66
"build": "webpack --mode=production",
@@ -38,6 +38,7 @@
3838
"babel-loader": "8.2.2",
3939
"browser-sync": "2.26.14",
4040
"browser-sync-webpack-plugin": "2.3.0",
41+
"browserslist": "4.16.6",
4142
"clean-webpack-plugin": "1.0.1",
4243
"create-pwa": "2.3.1",
4344
"critical": "3.1.0",
@@ -69,6 +70,7 @@
6970
"spritesh": "1.2.1",
7071
"stylelint": "13.13.1",
7172
"stylelint-config-recommended": "5.0.0",
73+
"svgo": "2.3.0",
7274
"webpack": "5.38.1",
7375
"webpack-cli": "4.7.0",
7476
"webpack-shell-plugin-next": "2.2.2",

svgo.config.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// @ts-nocheck
2+
3+
const { extendDefaultPlugins } = require('svgo');
4+
5+
module.exports = {
6+
plugins: extendDefaultPlugins([
7+
{
8+
name: 'cleanupAttrs',
9+
active: true
10+
},
11+
{
12+
name: 'removeDoctype',
13+
active: true
14+
},
15+
{
16+
name: 'removeXMLProcInst',
17+
active: true
18+
},
19+
{
20+
name: 'removeComments',
21+
active: true
22+
},
23+
{
24+
name: 'removeMetadata',
25+
active: true
26+
},
27+
{
28+
name: 'removeUselessDefs',
29+
active: true
30+
},
31+
{
32+
name: 'removeEditorsNSData',
33+
active: true
34+
},
35+
{
36+
name: 'removeEmptyAttrs',
37+
active: true
38+
},
39+
{
40+
name: 'removeEmptyText',
41+
active: true
42+
},
43+
{
44+
name: 'removeEmptyContainers',
45+
active: true
46+
},
47+
{
48+
name: 'cleanupEnableBackground',
49+
active: true
50+
},
51+
{
52+
name: 'convertStyleToAttrs',
53+
active: true
54+
},
55+
{
56+
name: 'removeUselessStrokeAndFill',
57+
active: true
58+
},
59+
{
60+
name: 'cleanupIDs',
61+
active: true,
62+
params: {
63+
prefix: {
64+
toString() {
65+
this.counter = this.counter || 0;
66+
67+
return `svgo-viewbox-id-${this.counter++}`;
68+
}
69+
}
70+
}
71+
},
72+
{
73+
name: 'removeDimensions',
74+
active: true
75+
}
76+
])
77+
};

webpack.config.js

+1-22
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,6 @@ if (server) {
2222
exec('php index.php > index.html');
2323
}
2424

25-
const svgoConfig = {
26-
plugins: [
27-
{ name: 'cleanupAttrs', active: true },
28-
{ name: 'removeDoctype', active: true },
29-
{ name: 'removeXMLProcInst', active: true },
30-
{ name: 'removeComments', active: true },
31-
{ name: 'removeMetadata', active: true },
32-
{ name: 'removeUselessDefs', active: true },
33-
{ name: 'removeEditorsNSData', active: true },
34-
{ name: 'removeEmptyAttrs', active: true },
35-
{ name: 'removeHiddenElems', active: false },
36-
{ name: 'removeEmptyText', active: true },
37-
{ name: 'removeEmptyContainers', active: true },
38-
{ name: 'cleanupEnableBackground', active: true },
39-
{ name: 'removeViewBox', active: false },
40-
{ name: 'cleanupIDs', active: false },
41-
{ name: 'convertStyleToAttrs', active: true },
42-
{ name: 'removeUselessStrokeAndFill', active: true }
43-
]
44-
};
45-
4625
const postcssOptions = {
4726
ident: 'postcss',
4827
plugins: [
@@ -152,7 +131,7 @@ const shellScripts = [];
152131
const svgs = readdirSync('./assets/images/svg').filter(svg => svg[0] !== '.');
153132

154133
if (svgs.length) {
155-
shellScripts.push('svgo -f assets/images/svg --config=' + JSON.stringify(svgoConfig));
134+
shellScripts.push('svgo -f assets/images/svg');
156135
shellScripts.push('spritesh -q -i assets/images/svg -o ./assets/dist/sprite.svg -p svg-');
157136
}
158137

0 commit comments

Comments
 (0)