Need help with grunt-svgmin?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

sindresorhus
436 Stars 47 Forks MIT License 88 Commits 2 Opened issues

Description

Minify SVG

Services available

!
?

Need anything else?

Contributors list

# 80
Shell
exec
test-fr...
nextjs
46 commits
# 59,497
CSS
js
React
high-or...
7 commits
# 458,936
spigot
CSS
c-plus-...
tileset...
1 commit
# 146,676
CSS
HTML
Shell
twig
1 commit
# 52,313
Algolia
GraphQL
capistr...
Vue.js
1 commit
# 23,111
imagemi...
clean-c...
Svelte
Babel
1 commit
# 3,548
memory-...
vuejs
Nuxt.js
xamarin...
1 commit
# 5,217
TypeScr...
React
phantom...
prose
1 commit
# 352,124
JavaScr...
Shell
1 commit
# 183,459
Scala
HTML
Shell
React
1 commit
# 651,192
JavaScr...
1 commit
# 651,193
JavaScr...
1 commit
# 384,447
CSS
HTML
1 commit
# 52,874
lodash
CSS
1-wire
pwm
1 commit
# 469,268
CSS
PHP
1 commit
# 193,491
HTML
Shell
Markdow...
postcss...
1 commit
# 231,095
PHP
Clojure
Shell
otf
1 commit
# 654,562
JavaScr...
1 commit
# 241
TypeScr...
Visual ...
CSS
vscode
1 commit
# 13,361
JavaScr...
nginx
React
HTML
1 commit

grunt-svgmin

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.