question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I can`t delete prefix in className in svg

See original GitHub issue

How I understand, @svgr/webpack add prefix (name of svg) for className (for React Project). For example, if my svg named ‘name1.svg’ and had class=“class1”, in browser I see className=“name1_class1”. I want delete prefix and I try use svgo plugin options:

    test: /\.svg$/,
      include: PATHS.images,
      use: [{
        loader: '@svgr/webpack',
        options: {
          svgoConfig: {
            plugins: [{
              prefixIds: false
            }]
          }
        }
      }]

Also I use another options:

    test: /\.svg$/,
      include: PATHS.images,
      use: [{
        loader: '@svgr/webpack',
        options: {
          svgoConfig: {
            plugins: [{
              cleanupIDs: {
                prefix: ''
              }
            }]
          }
        }
      }]

But it doesn`t work. Please, help me how delete a prefix for className

@svgr/webpack”: “^5.2.0”, “webpack”: “^4.41.5”,

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
gglutacommented, Oct 3, 2022

This is the correct config that eventually worked for me, with the mention that I am using NextJS, so the following snippet is part of my next.config.js file.

webpack: (config) => {
    config.module.rules.push({
      test: /\.svg$/i,
      issuer: /\.[jt]sx?$/,
      use: {
        loader: '@svgr/webpack',
        options: {
          svgoConfig: {
            plugins: [
              {
                name: 'prefixIds',
                active: false
              }
            ]
          }
        }
      }
    })
    return config
  }
0reactions
qizeng19commented, Jul 28, 2022

let me show you the direct code

      options:{
        svgo:true,
        svgoConfig : {
          plugins:[
            {
              name: "prefixIds",
              params: {
                prefixIds: false,
                prefixClassNames: false
              }
            },
          ]
        }
      }```
Read more comments on GitHub >

github_iconTop Results From Across the Web

prefix problem
I want my class name to match the name of the svg file(icon-graphic-phone). In the app is there a way to remove the...
Read more >
Unable to change class name of SVG element
In HTML, className is a string. In SVG it is an SVGAnimatedString object. That's why you can't just do svgElement.className = "halffill" ....
Read more >
Control of SVG <style> class names on Export
If I want several related/similar SVG files to use the same script or css, I can't be sure that the class name that...
Read more >
Specify CSS class names on SVG paths using Illustrator
I can't get illustrator to export with ID's, or classes's. I prefer to code my SVG's though, as odd as that sounds, and...
Read more >
fortawesome/fontawesome-svg-core Code Examples
createElement('button'); geolocationButton.classList = 'btn btn-danger btn-sm'; // Set icon const iconDef = findIconDefinition({prefix ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found