Skip to content

Commit 73ec0fe

Browse files
authored
Update the SVG sprite creation to use SVGO v2 (#906)
1 parent ca84179 commit 73ec0fe

File tree

4 files changed

+173
-133
lines changed

4 files changed

+173
-133
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-mpa-ts",
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",
@@ -74,6 +74,7 @@
7474
"spritesh": "1.2.1",
7575
"stylelint": "13.13.1",
7676
"stylelint-config-recommended": "5.0.0",
77+
"svgo": "2.3.0",
7778
"ts-loader": "9.2.2",
7879
"tslint": "6.1.3",
7980
"tslint-config-prettier": "1.18.0",

svgo.config.js

Lines changed: 77 additions & 0 deletions
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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,6 @@ if (server) {
3030
exec('php index.php > index.html');
3131
}
3232

33-
const svgoConfig = {
34-
plugins: [
35-
{ name: 'cleanupAttrs', active: true },
36-
{ name: 'removeDoctype', active: true },
37-
{ name: 'removeXMLProcInst', active: true },
38-
{ name: 'removeComments', active: true },
39-
{ name: 'removeMetadata', active: true },
40-
{ name: 'removeUselessDefs', active: true },
41-
{ name: 'removeEditorsNSData', active: true },
42-
{ name: 'removeEmptyAttrs', active: true },
43-
{ name: 'removeHiddenElems', active: false },
44-
{ name: 'removeEmptyText', active: true },
45-
{ name: 'removeEmptyContainers', active: true },
46-
{ name: 'cleanupEnableBackground', active: true },
47-
{ name: 'removeViewBox', active: false },
48-
{ name: 'cleanupIDs', active: false },
49-
{ name: 'convertStyleToAttrs', active: true },
50-
{ name: 'removeUselessStrokeAndFill', active: true }
51-
]
52-
};
53-
5433
const postcssOptions = {
5534
plugins: [postcssURL({ url: 'rebase' }), autoprefixer(), postcssUtilities, postcssEasyImport, postcssFlexbugsFixed],
5635
...sourceMap
@@ -124,7 +103,7 @@ const shellScripts = [];
124103
const svgs = readdirSync('./assets/images/svg').filter(svg => svg[0] !== '.');
125104

126105
if (svgs.length) {
127-
shellScripts.push('svgo -f assets/images/svg --config=' + JSON.stringify(svgoConfig));
106+
shellScripts.push('svgo -f assets/images/svg');
128107

129108
shellScripts.push('spritesh -q -i assets/images/svg -o ./assets/dist/sprite.svg -p svg-');
130109
}

0 commit comments

Comments
 (0)