How to use the svgo/plugins/removeAttrs.active function in svgo

To help you get started, we’ve selected a few svgo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nuxt-community / svg-sprite-module / lib / svg.js View on Github external
import Svgo from 'svgo'
import fs from 'fs-extra'
import cleanupIDs from 'svgo/plugins/cleanupIDs'
import removeAttrs from 'svgo/plugins/removeAttrs'
import removeDimensions from 'svgo/plugins/removeDimensions'
import removeViewBox from 'svgo/plugins/removeViewBox'
import inlineStyles from 'svgo/plugins/inlineStyles'
import inlineDefs from './plugins/inlineDefs'

// Enable removeAttrs plugin
// Remove id attribute to prevent conflict with our id
removeAttrs.active = true
removeAttrs.params.attrs = 'svg:id'

// Disable removeViewBox plugin and enable removeDimensions
// Keep viewBox and remove width & height attribute
removeViewBox.active = false
removeDimensions.active = true

// Make all styles inline
// By definition, a defs sprite is not usable as a CSS sprite
inlineStyles.active = true
inlineStyles.params.onlyMatchedOnce = false

const svgOptimizer = new Svgo({
  plugins: [
    removeDimensions,
    cleanupIDs,