Socket
Socket
Sign inDemoInstall

grunt-svgmin

Package Overview
Dependencies
193
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0 to 6.0.0

89

package.json
{
"name": "grunt-svgmin",
"version": "5.0.0",
"description": "Minify SVG",
"license": "MIT",
"repository": "sindresorhus/grunt-svgmin",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && grunt"
},
"files": [
"tasks"
],
"keywords": [
"gruntplugin",
"svg",
"vector",
"graphic",
"image",
"optimize",
"minify"
],
"dependencies": {
"chalk": "^2.3.0",
"each-async": "^1.1.1",
"log-symbols": "^2.1.0",
"pretty-bytes": "^4.0.2",
"svgo": "^1.0.3"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-simple-mocha": "^0.4.0",
"xo": "*"
},
"peerDependencies": {
"grunt": ">=0.4.0"
}
"name": "grunt-svgmin",
"version": "6.0.0",
"description": "Minify SVG",
"license": "MIT",
"repository": "sindresorhus/grunt-svgmin",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && grunt"
},
"files": [
"tasks"
],
"keywords": [
"gruntplugin",
"svg",
"vector",
"graphic",
"image",
"optimize",
"minify"
],
"dependencies": {
"chalk": "^2.4.2",
"log-symbols": "^2.2.0",
"pretty-bytes": "^5.1.0",
"svgo": "^1.2.0"
},
"devDependencies": {
"grunt": "^1.0.3",
"grunt-cli": "^1.3.2",
"grunt-contrib-clean": "^2.0.0",
"grunt-simple-mocha": "^0.4.1",
"xo": "^0.24.0"
},
"peerDependencies": {
"grunt": ">=1"
}
}

@@ -18,3 +18,3 @@ # grunt-svgmin [![Build Status](https://travis-ci.org/sindresorhus/grunt-svgmin.svg?branch=master)](https://travis-ci.org/sindresorhus/grunt-svgmin)

```js
require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks
require('load-grunt-tasks')(grunt);

@@ -27,7 +27,11 @@ grunt.initConfig({

removeViewBox: false
}, {
},
{
removeUselessStrokeAndFill: false
}, {
},
{
removeAttrs: {
attrs: ['xmlns']
attrs: [
'xmlns'
]
}

@@ -57,3 +61,3 @@ }

plugins: [
{removeViewBox: false}, // Don't remove the viewbox atribute from the SVG
{removeViewBox: false}, // Don't remove the viewbox attribute from the SVG
{removeUselessStrokeAndFill: false}, // Don't remove Useless Strokes and Fills

@@ -72,3 +76,5 @@ {removeEmptyAttrs: false} // Don't remove Empty Attributes from the SVG

removeAttrs: {
attrs: ['xmlns']
attrs: [
'xmlns'
]
}

@@ -75,0 +81,0 @@ }

'use strict';
const chalk = require('chalk');
const eachAsync = require('each-async');
const prettyBytes = require('pretty-bytes');

@@ -9,31 +8,28 @@ const logSymbols = require('log-symbols');

module.exports = grunt => {
grunt.registerMultiTask('svgmin', 'Minify SVG', function () {
grunt.registerMultiTask('svgmin', 'Minify SVG', async function () {
const done = this.async();
const svgo = new SVGO(this.options());
let totalSaved = 0;
let totalSavedBytes = 0;
eachAsync(this.files, (el, i, next) => {
const srcPath = el.src[0];
const srcSvg = grunt.file.read(srcPath);
await Promise.all(this.files.map(async element => {
const sourcePath = element.src[0];
const sourceSvg = grunt.file.read(sourcePath);
svgo.optimize(srcSvg).then(result => {
if (result.error) {
grunt.warn(srcPath + ': ' + result.error);
next();
return;
}
const result = await svgo.optimize(sourceSvg, {srcPath: sourcePath});
if (result.error) {
grunt.warn(`${sourcePath}: ${result.error}`);
return;
}
const saved = srcSvg.length - result.data.length;
const percentage = saved / srcSvg.length * 100;
totalSaved += saved;
const savedBytes = sourceSvg.length - result.data.length;
const percentage = savedBytes / sourceSvg.length * 100;
totalSavedBytes += savedBytes;
grunt.verbose.writeln(logSymbols.success + ' ' + srcPath + chalk.gray(' (saved ' + chalk.bold(prettyBytes(saved)) + ' ' + Math.round(percentage) + '%)'));
grunt.file.write(el.dest, result.data);
next();
});
}, () => {
grunt.log.writeln('Total saved: ' + chalk.green(prettyBytes(totalSaved)));
done();
});
grunt.verbose.writeln(logSymbols.success + ' ' + sourcePath + chalk.gray(' (saved ' + chalk.bold(prettyBytes(savedBytes)) + ' ' + Math.round(percentage) + '%)'));
grunt.file.write(element.dest, result.data);
}));
grunt.log.writeln(`Total saved: ${chalk.green(prettyBytes(totalSavedBytes))}`);
done();
});
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc