Socket
Socket
Sign inDemoInstall

grunt-svgmin

Package Overview
Dependencies
4
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    grunt-svgmin

Minify SVG


Version published
Maintainers
1
Install size
7.54 MB
Created

Readme

Source

grunt-svgmin Build Status

Minify SVG using SVGO

Issues with the output should be reported on the SVGO issue tracker.

Install

$ npm install --save-dev grunt-svgmin

Usage

require('load-grunt-tasks')(grunt);

grunt.initConfig({
	svgmin: {
		options: {
			plugins: [
				{
					removeViewBox: false
				},
				{
					removeUselessStrokeAndFill: false
				},
				{
					removeAttrs: {
						attrs: [
							'xmlns'
						]
					}
				}
			]
		},
		dist: {
			files: {
				'dist/unicorn.svg': 'app/unicorn.svg'
			}
		}
	}
});

grunt.registerTask('default', ['svgmin']);

Available Options/Plugins

This module makes use of the standard SVGO plugin architecture. Therefore, to customize SVG optimization, you can disable/enable/configure any SVGO plugins listed at the SVGO repository.

To disable plugins with the gruntfile.js, look for the plugin name at the SVGO repository and copy the plugin name (minus the file extension). Then set its value in the JSON to false in comma-separated objects. To exemplify, here is how the plugins section in the example configuration (illustrated above) might be written with some of the standard SVGO plugins disabled:

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

Check each plugin for exports.active = [true/false] to see if the plugin is enabled. Most of the plugins are enabled by default but you may want to prevent a couple, particularly removeUselessStrokeAndFill as that may remove small details with subtracted / extruded complex paths.

To configure specific parameters for a plugin with the gruntfile.js, set its value in the JSON to a params object:

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

Check each plugin for exports.params to see if it has default parameters and what they are.

Note

Per-file savings are only printed in verbose mode (grunt svgmin --verbose).

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 31 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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