Vue-svg-loader: identical id in different svg

Created on 24 Nov 2018  路  6Comments  路  Source: visualfanatic/vue-svg-loader

as a result, svg in such format https://pastebin.com/m5hMA2A0 convert to https://pastebin.com/Ah1CVRcw

loader change id from path-1jaksljkaslasbf to a

import more than 1 svg with this format to page leads to visual display of two identical svg

P.S. i'm not good with english and not familiar with github, but i found this bug

Most helpful comment

@visualfanatic this works, you may want to include it in the docs

// vue.config.js
module.exports = {
  chainWebpack: config => {
    const svgRule = config.module.rule('svg')
    // clear all existing loaders.
    // if you don't do this, the loader below will be appended to
    // existing loaders of the rule.
    svgRule.uses.clear()

    // add replacement loader(s)
    svgRule
      .use('vue-svg-loader')
        .loader('vue-svg-loader')
          .options({
                    svgo: {
                      plugins: [
                        {"cleanupIDs": false},
                        {"convertShapeToPath": false},
                        {"convertStyleToAttrs": false},
                      ]
                    }
                  })
  },
  transpileDependencies: [
  // can be string or regex
  'my-dep',
  /other-dep/
]
}

All 6 comments

This is not a bug, you can disable this behavior:

{
  test: /\.svg$/,
  loader: 'vue-svg-loader',
  options: {
    svgo: {
      plugins: [
        { cleanupIDs: false },
      ],
    },
  },
},

thanks, where a can find options documentation?

Right now the only property that you can customize is svgo which is an object that is passed to SVGO library. Here is a list of available plugins that you can customize:
https://github.com/svg/svgo

@sashakaralchuk does the example I posted above works for you?

@visualfanatic if im using vue cli 3 would it be like this?

  chainWebpack: config => {
    const svgRule = config.module.rule('svg')
    const svgoConfig = {
                        svgo: {
                           plugins: [{
                              cleanupIDs: false,
                              convertShapeToPath: false
                            }]
                        }
                      }
    // clear all existing loaders.
    // if you don't do this, the loader below will be appended to
    // existing loaders of the rule.
    svgRule.uses.clear()

    // add replacement loader(s)
    svgRule
      .use('vue-svg-loader')
        .loader('vue-svg-loader')
            .options(svgoConfig)
  },

@visualfanatic this works, you may want to include it in the docs

// vue.config.js
module.exports = {
  chainWebpack: config => {
    const svgRule = config.module.rule('svg')
    // clear all existing loaders.
    // if you don't do this, the loader below will be appended to
    // existing loaders of the rule.
    svgRule.uses.clear()

    // add replacement loader(s)
    svgRule
      .use('vue-svg-loader')
        .loader('vue-svg-loader')
          .options({
                    svgo: {
                      plugins: [
                        {"cleanupIDs": false},
                        {"convertShapeToPath": false},
                        {"convertStyleToAttrs": false},
                      ]
                    }
                  })
  },
  transpileDependencies: [
  // can be string or regex
  'my-dep',
  /other-dep/
]
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MattCCC picture MattCCC  路  6Comments

valangar picture valangar  路  3Comments

andreasvirkus picture andreasvirkus  路  5Comments

psulkava picture psulkava  路  3Comments

Chucheen picture Chucheen  路  5Comments