about summary refs log tree commit diff
path: root/svgo.config.mjs
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-09-24 15:31:41 +0100
committerGitHub <noreply@github.com>2024-09-24 15:31:41 +0100
commitb626b93417a5c1fd5f91b3641fb095f7ac50abf1 (patch)
tree31ea4381fb7b44fc9594727b54d41ef81dcfb58d /svgo.config.mjs
parenta1e212ab59c9bd98b0923a7911c5140c3f10ac25 (diff)
downloadvoidsky-b626b93417a5c1fd5f91b3641fb095f7ac50abf1.tar.zst
Automatically optimise SVG assets (#5467)
* add svgo as dev dep

* prefer viewbox

* manual config

* fix config param names

* align config with svgomg

* add lint-staged svgo hook

* edit hook

* add trailing whitespace plugin

* run svgo on existing assets
Diffstat (limited to 'svgo.config.mjs')
-rw-r--r--svgo.config.mjs64
1 files changed, 64 insertions, 0 deletions
diff --git a/svgo.config.mjs b/svgo.config.mjs
new file mode 100644
index 000000000..d7c98cd54
--- /dev/null
+++ b/svgo.config.mjs
@@ -0,0 +1,64 @@
+const preset = [
+  "removeDoctype",
+  "removeXMLProcInst",
+  "removeComments",
+  "removeMetadata",
+  "removeEditorsNSData",
+  "cleanupAttrs",
+  "mergeStyles",
+  "inlineStyles",
+  "minifyStyles",
+  "cleanupIds",
+  "removeUselessDefs",
+  "cleanupNumericValues",
+  "convertColors",
+  "removeUnknownsAndDefaults",
+  "removeNonInheritableGroupAttrs",
+  "removeUselessStrokeAndFill",
+  "removeDimensions",
+  "cleanupEnableBackground",
+  "removeHiddenElems",
+  "removeEmptyText",
+  "convertShapeToPath",
+  "convertEllipseToCircle",
+  "moveElemsAttrsToGroup",
+  "moveGroupAttrsToElems",
+  "collapseGroups",
+  "convertPathData",
+  "convertTransform",
+  "removeEmptyAttrs",
+  "removeEmptyContainers",
+  "removeUnusedNS",
+  "mergePaths",
+  "sortAttrs",
+  "sortDefsChildren",
+  "removeTitle",
+  "removeDesc",
+]
+
+export default {
+  plugins: [...preset.map(name => ({
+    name,
+    params: {
+      floatPrecision: 3,
+      transformPrecision: 5,
+      // minimise diff in ouput from svgomg
+      // maybe remove in future? will produce smaller output
+      convertToZ: false,
+      removeUseless: false,
+    }
+  })),
+  {
+    name: 'addTrailingWhitespace',
+    fn() {
+      return {
+        root: {
+          exit (root) {
+            root.children.push({ type: 'text', value: '\n' })
+            return root
+          }
+        }
+      }
+    }
+  }]
+};