Skip to content

Commit c5fb607

Browse files
committed
refactor: update SVGO configuration for compatibility with SVGO 3
- Modified the SVGO configuration to align with SVGO 3 standards, replacing the old plugin format with the new preset-default structure. - Adjusted the plugins list in plugins.js to ensure proper integration of the updated svgoconfig. - This change enhances image optimization while maintaining compatibility with the latest SVGO version.
1 parent fc805ae commit c5fb607

2 files changed

Lines changed: 37 additions & 35 deletions

File tree

config/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports = {
6666
['gifsicle', { interlaced: true }],
6767
['jpegtran', { progressive: true }],
6868
['optipng', { optimizationLevel: 5 }],
69-
['svgo', { svgoconfig }],
69+
['svgo', svgoconfig],
7070
],
7171
},
7272
},

config/svgo.config.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
1+
/**
2+
* SVGO 3+ config for imagemin-svgo / svgo-loader.
3+
*
4+
* Format: SVGO 3 rejects the v2 style `{ cleanupAttrs: true }` (no `name` on plugin objects).
5+
*
6+
* Why not list every plugin like the old file?
7+
* - SVGO 3 expects either named plugins or `preset-default`, which bundles most optimizers
8+
* (cleanupAttrs, removeComments, convertPathData, mergePaths, etc.) in a maintained order.
9+
* Duplicating that full list in v3 `{ name, params }` form would be long and redundant.
10+
* - Reference: https://svgo.dev/docs/preset-default/
11+
*
12+
* Mapping from the previous v2 `{ plugin: boolean }` list:
13+
* - `true` on a built-in → usually covered by `preset-default` (see link above).
14+
* - `false` falls into two cases in SVGO 3:
15+
* (A) Plugin is part of `preset-default` → turn it off with `params.overrides`
16+
* (e.g. `removeViewBox: false` below — removeViewBox runs inside the preset by default).
17+
* (B) Plugin is optional / not in the preset → do not list it; SVGO only runs plugins you
18+
* declare. So “false” in v2 = omit the plugin name here.
19+
* Examples from the old config:
20+
* - removeDimensions: https://svgo.dev/docs/plugins/removeDimensions/ — optional; not in
21+
* `preset-default`; we omit it so width/height stay (unless you add `'removeDimensions'`).
22+
* - removeRasterImages: https://svgo.dev/docs/plugins/removeRasterImages/ — optional;
23+
* not in `preset-default`; we omit it so embedded rasters are kept.
24+
* - Extra plugins the old list enabled but preset does not include:
25+
* `convertStyleToAttrs`, `prefixIds` — listed explicitly below (sprites / ID stability).
26+
*/
127
module.exports = {
228
plugins: [
3-
{ cleanupAttrs: true },
4-
{ removeDoctype: true },
5-
{ removeXMLProcInst: true },
6-
{ removeComments: true },
7-
{ removeMetadata: true },
8-
{ removeTitle: true },
9-
{ removeDesc: true },
10-
{ removeUselessDefs: true },
11-
{ removeEditorsNSData: true },
12-
{ removeEmptyAttrs: true },
13-
{ removeHiddenElems: true },
14-
{ removeEmptyText: true },
15-
{ removeEmptyContainers: true },
16-
{ cleanupEnableBackground: true },
17-
{ convertStyleToAttrs: true },
18-
{ convertColors: true },
19-
{ convertPathData: true },
20-
{ convertTransform: true },
21-
{ removeUnknownsAndDefaults: true },
22-
{ removeNonInheritableGroupAttrs: true },
23-
{ removeUselessStrokeAndFill: true },
24-
{ removeUnusedNS: true },
25-
{ cleanupIDs: true },
26-
{ cleanupNumericValues: true },
27-
{ moveElemsAttrsToGroup: true },
28-
{ moveGroupAttrsToElems: true },
29-
{ collapseGroups: true },
30-
{ removeRasterImages: false },
31-
{ mergePaths: true },
32-
{ convertShapeToPath: true },
33-
{ sortAttrs: true },
34-
{ removeDimensions: false },
35-
{ prefixIds: true },
36-
{ removeViewBox: false },
29+
{
30+
name: 'preset-default',
31+
params: {
32+
overrides: {
33+
removeViewBox: false,
34+
},
35+
},
36+
},
37+
'convertStyleToAttrs',
38+
'prefixIds',
3739
],
3840
}

0 commit comments

Comments
 (0)