diff --git a/.svgo.yml b/.svgo.yml index 59bcb742..43a15d5b 100644 --- a/.svgo.yml +++ b/.svgo.yml @@ -22,6 +22,7 @@ plugins: - removeMetadata - removeEditorsNSData - cleanupAttrs + - minifyStyles - convertStyleToAttrs - cleanupIDs - removeRasterImages diff --git a/package.json b/package.json index 229049c0..eb9e125e 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "js-yaml": "~3.3.1", "colors": "~1.1.2", "whet.extend": "~0.9.9", - "mkdirp": "~0.5.1" + "mkdirp": "~0.5.1", + "csso": "~1.4.1" }, "devDependencies": { "mocha": "~2.2.5", diff --git a/plugins/minifyStyles.js b/plugins/minifyStyles.js new file mode 100755 index 00000000..554609d0 --- /dev/null +++ b/plugins/minifyStyles.js @@ -0,0 +1,71 @@ +'use strict'; + +exports.type = 'perItem'; + +exports.active = true; + +exports.params = { + svgo: {} +}; + +exports.description = 'minifies existing styles in svg'; + +var csso = require('csso'); + + +// wraps css rules into a selector to make it parseable +var rulesToDummySelector = function(str) { + return '.dummy { ' + str + ' }'; +}; + +// helper to extract css rules from full css selector +var extractRuleCss = function(str) { + var strEx = str.match(/\.dummy{(.*)}/i)[1]; + return strEx; +}; + +// minifies css using csso +var minifyCss = function(css, options) { + return csso.minify(css); +}; + + + +/** + * Minifies styles ( + + + +@@@ + + + + +