Vue-svg-loader: How to use prefix option with cleanupIDs

Created on 15 Nov 2018  路  2Comments  路  Source: visualfanatic/vue-svg-loader

I cannot handle how to configure this loader with custom options for svggo.

The problem is that my SVGs are conflicting because all of they have the same ids (a, b, c, etc). I found a solution on svggo options:
{ cleanupIDs: { prefix: 'somerandomid' } }

But, I cannot figure out how to customize the webpack config for this option.

I've tried this

config.module.rules = config.module.rules.map(rule => {
  if (rule.loader === 'vue-svg-loader') {
    return {
      test: /\.svg$/,
      loader: 'vue-svg-loader',
      options: {
        svggo: {
          plugins: [
            { cleanupIDs: { prefix: 'somerandomid' } },
          ]
        }
      }
    }
  }

  return rule
})

and this

config.module.rules = config.module.rules.map(rule => {
  if (rule.loader === 'vue-svg-loader') {
    return {
      test: /\.svg$/,
      use: () => ({
        loader: 'vue-svg-loader',
        options: {
          plugins: [
            { 
              cleanupIDs: { prefix: crypto.randomBytes(4).toString('hex') }
            },
          ],
        },
      }),
    }
  }

  return rule
})

But without success, am I doing something wrong?

Most helpful comment

Have you checked this section in FAQ?
https://vue-svg-loader.js.org/faq.html#how-to-prefix-id-attributes

All 2 comments

Have you checked this section in FAQ?
https://vue-svg-loader.js.org/faq.html#how-to-prefix-id-attributes

@visualfanatic,

Thank you. That worked

// SVG Rules
config.module.rules = config.module.rules.map(rule => {
  if (rule.loader === 'vue-svg-loader') {
    return {
      test: /\.svg$/,
      loader: 'vue-svg-loader',
      options: {
        svgo: {
          plugins: [
            { prefixIds: true },
          ]
        }
      }
    }
  }

  return rule
})
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jpetko picture jpetko  路  5Comments

andreasvirkus picture andreasvirkus  路  5Comments

jdfx picture jdfx  路  7Comments

psulkava picture psulkava  路  3Comments

leopoldkristjansson picture leopoldkristjansson  路  5Comments