Skip to content

Commit ebc60de

Browse files
authored
Update the SVG sprite creation to use SVGO v2 (#688)
1 parent 6954391 commit ebc60de

File tree

4 files changed

+409
-499
lines changed

4 files changed

+409
-499
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-mpa",
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",
@@ -39,6 +39,7 @@
3939
"babel-loader": "8.2.2",
4040
"browser-sync": "2.26.14",
4141
"browser-sync-webpack-plugin": "2.3.0",
42+
"browserslist": "4.16.6",
4243
"clean-webpack-plugin": "1.0.1",
4344
"create-pwa": "2.3.1",
4445
"critical": "3.1.0",
@@ -64,6 +65,7 @@
6465
"spritesh": "1.2.1",
6566
"stylelint": "13.13.1",
6667
"stylelint-config-recommended": "5.0.0",
68+
"svgo": "2.3.0",
6769
"webpack": "5.38.1",
6870
"webpack-cli": "4.7.0",
6971
"webpack-shell-plugin-next": "2.2.2",

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
@@ -23,27 +23,6 @@ if (server) {
2323
exec('php index.php > index.html');
2424
}
2525

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

138117
if (svgs.length) {
139-
shellScripts.push('svgo -f assets/images/svg --config=' + JSON.stringify(svgoConfig));
118+
shellScripts.push('svgo -f assets/images/svg');
140119
shellScripts.push('spritesh -q -i assets/images/svg -o ./assets/dist/sprite.svg -p svg-');
141120
}
142121

0 commit comments

Comments
 (0)