Automatically compress SVGs with svgo

pull/70/head
Nikita Karamov 2023-07-15 11:36:09 +02:00
parent 000e3b1b1f
commit de9b21ed33
No known key found for this signature in database
GPG Key ID: 41D6F71EE78E77CD
2 changed files with 102 additions and 0 deletions

View File

@ -26,3 +26,13 @@ repos:
- eslint-config-prettier
- eslint-plugin-unicorn
- prettier@3
- repo: local
hooks:
- id: svgo
name: optimize SVG files
entry: svgo
types: [svg]
files: 'src/icons/.*\.svg'
language: node
additional_dependencies:
- "svgo"

92
svgo.config.js Normal file
View File

@ -0,0 +1,92 @@
/*!
* SVGO configuration from simple-icons, modified.
*
* See: https://github.com/simple-icons/simple-icons/blob/4e36921e759278e83f2e6775e0fb78ba76131eec/svgo.config.mjs
*/
export default {
multipass: true,
eol: "lf",
plugins: [
"cleanupAttrs",
"mergeStyles",
"minifyStyles",
"inlineStyles",
"removeDoctype",
"removeXMLProcInst",
"removeComments",
"removeMetadata",
"removeDesc",
"removeUselessDefs",
"removeEditorsNSData",
"removeEmptyAttrs",
"removeHiddenElems",
"removeEmptyText",
"removeEmptyContainers",
"convertStyleToAttrs",
"convertColors",
"cleanupEnableBackground",
{
name: "convertPathData",
params: {
// 3 decimals of precision in floating point numbers
floatPrecision: 3,
},
},
"convertTransform",
{
name: "removeUnknownsAndDefaults",
},
"removeUselessStrokeAndFill",
"removeNonInheritableGroupAttrs",
"removeUnusedNS",
"cleanupIds",
"cleanupNumericValues",
"cleanupListOfValues",
"collapseGroups",
"removeRasterImages",
{
// Compound all <path>s into one
name: "mergePaths",
params: {
force: true,
},
},
{
// Convert basic shapes (such as <circle>) to <path>
name: "convertShapeToPath",
params: {
// including <arc>
convertArcs: true,
},
},
"convertEllipseToCircle",
{
// Sort the attributes on the <svg> tag
name: "sortAttrs",
params: {
order: ["fill", "stroke", "viewBox"],
xmlnsOrder: "end",
},
},
"sortDefsChildren",
"removeDimensions",
{
name: "removeAttrs",
params: {
attrs: ["svg:(?!(role|xmlns))", "path:(?!d)"],
},
},
{
name: "addAttributesToSVGElement",
params: {
attributes: [{ xmlns: "http://www.w3.org/2000/svg" }],
},
},
"removeOffCanvasPaths",
"removeStyleElement",
"removeScriptElement",
"removeTitle",
],
};