svgo-add-viewbox
SVGO Add viewBox
An SVGO plugin to add
viewBox
attribute based onwidth
andheight
attributes
Visitor stats
Code stats
This plugin adds the viewBox
attribute to your SVGs based on the width
and height
attributes. The difference between this plugin and the built-in removeDimensions
plugin is that svgo-add-viewbox
does not remove the width
and height
of your SVGs.
In order to use this plugin correctly, you SVGs should have their width
and height
attributes specified.
Usage
v2.x.x of this plugin should be used with SVGO v3 and above.
v1.x.x of this plugin should be used with SVGO v2.
- Create a
svgo.config.js
file following the official configuration guide - Use the option to specify a custom plugin.
- Install this module from NPM
npm install svgo-add-viewbox --save-dev # or yarn add svgo-add-viewbox -D
require
the module which you just created in yoursvgo.config.js
file:const addViewBox = require('svgo-add-viewbox');
- In the
plugins
array in yoursvgo.config.js
file add the following:plugins: [ // ... more plugins { fn: addViewBox.fn, name: 'addViewBox', type: addViewBox.type, active: addViewBox.active, description: addViewBox.description } // ... more plugins ];
- Execute your SVG transformation NPM script.
LICENSE
MIT
Connect with me: