Commit 08e527a

HPCesia <me@hpcesia.com>
2026-03-11 12:54:31
Compress output SVGs
1 parent c061264
Changed files (1)
src
integrations
src/integrations/extract-image.ts
@@ -53,11 +53,21 @@ export const extractImage = defineIntegration({
 
                   if (!seenImages.has(filename)) {
                     seenImages.add(filename);
-                    const imageBuffer = Buffer.from(base64Data, "base64");
-                    await fs.writeFile(
-                      path.join(outDir, filename),
-                      imageBuffer,
-                    );
+                    const imageFilePath = path.join(outDir, filename);
+
+                    if (filename.endsWith(".svg")) {
+                      const svgStr = Buffer.from(base64Data, "base64").toString(
+                        "utf-8",
+                      );
+                      const minifiedSvg = svgStr
+                        .replace(/>\s+</g, "><")
+                        .replace(/\s{2,}/g, " ")
+                        .trim();
+                      await fs.writeFile(imageFilePath, minifiedSvg, "utf-8");
+                    } else {
+                      const imageBuffer = Buffer.from(base64Data, "base64");
+                      await fs.writeFile(imageFilePath, imageBuffer);
+                    }
                   }
 
                   $(el).attr("src", `/${options.dir}/${filename}`);