From cc22ad9b1fc48aa10561eda05e7245205c4e9967 Mon Sep 17 00:00:00 2001 From: codecalm Date: Thu, 15 Oct 2020 18:09:19 +0200 Subject: icons optimize --- gulpfile.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'gulpfile.js') diff --git a/gulpfile.js b/gulpfile.js index 8f6da156..1817ff9d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,6 +13,7 @@ const gulp = require('gulp'), sass = require('node-sass'), cleanCSS = require('clean-css'), argv = require('minimist')(process.argv.slice(2)), + svgParse = require('parse-svg-path'), svgpath = require('svgpath'), svgr = require('@svgr/core').default; @@ -406,6 +407,17 @@ gulp.task('optimize', function (cb) { return Math.round((parseFloat(n1) + parseFloat(n2)) * 1000) / 1000 }; + const optimizePath = function(path) { + let transformed = svgpath(path) + .rel() + .round(3) + .toString(); + + return svgParse(transformed).map(function(a){ + return a.join(' '); + }).join(' '); + }; + glob("src/_icons/*.svg", {}, function (er, files) { files.forEach(function (file, i) { @@ -418,6 +430,11 @@ gulp.task('optimize', function (cb) { .replace(/\s?\/>/g, ' />') .replace(/\n\s*<(line|circle|path|polyline|rect)/g, "\n <$1") .replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"') + .replace(/