Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep ids when loading SVG with @svgr/webpack?

I am loading SVG files with @svgr/webpack into React, I works fine but it strips the ids of the elements.
In order to keep the ids, I saw the option cleanIDs in SVGO config file, which I set to false, but to no avail.
How can I keep my ids?

Here is how I configure the loader in webpacks:

{
  test: /\.svg$/,
  use: [
    {
      loader: "@svgr/webpack",
      options: {
        cleanIDs: false,
      },
    },
  ],
},

I also tried:

  • to disable SVGO altogether, but then it fails to load the SVG files
  • with option cleanupIDs, but the ids are still removed
like image 961
Louis Coulet Avatar asked Oct 24 '25 10:10

Louis Coulet


1 Answers

This config worked for me on @svgr/[email protected]:

use: [
  {
    loader: "@svgr/webpack",
    options: {
      svgoConfig: {
        plugins: [
          {
            cleanupIDs: false
          }
        ]
      }
    }
  }
]

Some links that helped me figure this out:

  • svgo webpack example
  • svgo config options
like image 99
heidi Avatar answered Oct 27 '25 01:10

heidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!