Skip to content

Commit

Permalink
Add SVGO v2 config. Drop SVGO v1 support!
Browse files Browse the repository at this point in the history
BREAKING CHANGE!

This commit provides the new config file for svgo 2.0.0+ and removes
the config file for svgo 1.3.2 and lower.

To continue use tools in the project, please upgrade svgo to the latest
version:

npm install -g svgo
  • Loading branch information
SmartFinn committed Feb 18, 2021
1 parent 24665e6 commit c06ce6c
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 142 deletions.
2 changes: 1 addition & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* `_clean_style_attr.sed` — removes unused properties and removes properties with default values from style attributes inside SVG files (part of `ffsvg.sh`)
* `_fix_color_scheme.sh FILE...` — looks in the SVG files for certain colors and replaces them with the corresponding stylesheet class. Fixes a color scheme after Inkscape (part of `ffsvg.sh`)
* `_scour.sh FILE...` — Scour wrapper (part of `ffsvg.sh`)
* `_svgo.yml`[SVGO](https://github.com/svg/svgo) configuraion (part of `ffsvg.sh`)
* `svgo.config.js`[SVGO](https://github.com/svg/svgo) configuraion (part of `ffsvg.sh`)


## Useful snippets
Expand Down
140 changes: 0 additions & 140 deletions tools/_svgo.yml

This file was deleted.

2 changes: 1 addition & 1 deletion tools/ffsvg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _run_helpers() {
# optimize a SVG
if command -v svgo > /dev/null 2>&1; then
# use SVGO
svgo --config="$SCRIPT_DIR/_svgo.yml" -i "$1" -o "$1".tmp
svgo --config="$SCRIPT_DIR/svgo.config.js" -i "$1" -o "$1".tmp
mv -f "$1".tmp "$1"
elif command -v scour > /dev/null 2>&1; then
# use scour
Expand Down
117 changes: 117 additions & 0 deletions tools/svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
module.exports = {
multipass: true,
plugins: [
// remove DOCTYPE declaration
'removeDoctype',
// remove XML processing instructions
'removeXMLProcInst',
// remove comments
'removeComments',
// remove <metadata>
'removeMetadata',
// remove editors namespaces, elements and attributes
'removeEditorsNSData',
// cleanup attributes values from newlines, trailing and repeating spaces
'cleanupAttrs',
/**
* {
* // remove unused IDs
* name: 'cleanupIDs',
* params: {
* minify: false,
* preserve: ['current-color-scheme']
* }
* },
*/
// remove raster images references in <image>
'removeRasterImages',
// remove elements in <defs> without id
'removeUselessDefs',
{
// round numeric values to the fixed precision
// remove default 'px' units
// y="749.936002px" --> y="749.936"
name: 'cleanupNumericValues',
params: { convertToPx: false }
},
{
// round list of values to the fixed precision
// viewBox="0 0 16px 16px" --> viewBox="0 0 16 16"
name: 'cleanupListOfValues',
params: {
floatPrecision: 2,
leadingZero: true,
defaultPx: true,
convertToPx: false,
}
},
{
// convert different colors formats to #rrggbb
name: 'convertColors',
params: {
shorthex: false,
shortname: false,
}
},
/**
* {
* // remove unknown elements content and attributes
* // don't touch attributes with default values
* name: 'removeUnknownsAndDefaults',
* params: { defaultAttrs: false }
* },
*/
// remove viewBox attr which coincides with a width/height box
'removeViewBox',
// remove or cleanup enable-background attribute when possible
'cleanupEnableBackground',
{
// remove hidden elements (zero sized, with absent attributes)
name: 'removeHiddenElems',
params: { opacity0: false }
},
// remove empty <text/>, <tspan/>, and <tref xlink:href=""/> elements
'removeEmptyText',
// convert non-eccentric <ellipse> to <circle>
'convertEllipseToCircle',
// remove attributes with empty values
'removeEmptyAttrs',
// remove empty containers
'removeEmptyContainers',
// remove unused namespaces declaration
'removeUnusedNS',
{
// sort element attributes for epic readability
name: 'sortAttrs',
params: {
order: [
'id',
'fill', 'stroke', 'opacity',
'style', 'class',
'width', 'height',
'x', 'x1', 'x2',
'y', 'y1', 'y2',
'cx', 'cy',
'rx', 'ry', 'r',
'transform',
'marker',
'points',
'd',
]
}
},
// remove <title>
'removeTitle',
// remove <desc>
'removeDesc',
// remove elements that are drawn outside of the viewbox
// 'removeOffCanvasPaths',
],

// configure the indent (default 4 spaces) used by `--pretty` here:
// @see https://github.com/svg/svgo/blob/master/lib/svgo/js2svg.js#L6 for more config options
js2svg: {
pretty: true,
indent: 1
}
}

0 comments on commit c06ce6c

Please sign in to comment.