svgo-add-viewbox

SVGO plugin which adds 'viewBox' attribute based on 'width' and 'height' attributes

Usage no npm install needed!

<script type="module">
  import svgoAddViewbox from 'https://cdn.skypack.dev/svgo-add-viewbox';
</script>

README

SVGO Add viewBox npm MIT license Twitter Analytics

An SVGO plugin to add viewBox attribute based on width and height attributes

All issues on Github Open issues on Github Closed issues on Github Latest Github gag GitHub last commit

Weekly downloads on NPM Monthly downloads on NPM Yearly downloads on NPM Total downloads on NPM

Githib build status Combined Github checks Publish size Top language Used languages count Renovate App Status Make A Pull Request

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

This plugin should be used with SVGO v2 and above.

  1. Create a svgo.config.js file following the official configuration guide
  2. Use the option to specify a custom plugin.
  3. Install this module from NPM
    npm install svgo-add-viewbox --save-dev
    # or
    yarn add svgo-add-viewbox -D
    
  4. require the module which you just created in your svgo.config.js file:
    const addViewBox = require('svgo-add-viewbox');
    
  5. In the plugins array in your svgo.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
    ];
    
  6. Execute your SVG transformation NPM script.

Support this project

Tweet Donate on PayPal Become a Patron Buy Me A Coffee Donate on Liberapay Donate on Issuehunt

LICENSE

MIT