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.

Remove Style Element is an essential SVGO Plugin

See original GitHub issue

First of all, thank you for this loader, it’s a great idea!

I want to load several SVG icons using this loaded, but it always removes the <style> Element of the SVG, which is not what I want. I need the <style> Element to stay in place as it contains icon-specific options. I tried to disable the corresponding SVGO plugin using

            query: {
              svgo: {
                plugins: [
                  { removeStyleElement: false },
                ]
              }
            }

But this has no effect. Digging deeper, I noticed that removeStyleElement is a core plugin:

var essentialPlugins = ["removeDoctype", "removeComments", "removeStyleElement"];

It seems that I have no possibility to disable this plugin, is that correct? In this case, I could no longer use this project, which is quite sad. Is there really no option to disable removing the <style> element?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
butchlercommented, Mar 19, 2018

If the SVGO version this loader uses is updated (see https://github.com/boopathi/react-svg-loader/issues/192), then you could use the new inlineStyles SVGO plugin (https://github.com/svg/svgo/blob/master/plugins/inlineStyles.js) to automatically convert everything in <style> to inline attributes on the individual paths/etc. (essentially the same approach as saving the SVG with inline CSS in your editor, but done via this loader for you automatically).

1reaction
niyan-lycommented, Jan 6, 2018

if you are using adobe illustrator, you can change the svg styling format to “inline-css” via change the Asset Export panel’s setting. And in sketch and Affinity Designer, it’s a default option of using “inline-css” screen shot 2018-01-06 at 5 49 25 pm

Read more comments on GitHub >

github_iconTop Results From Across the Web

SVGR (SVGO) removeAttrs does not remove specified fill ...
When I manually remove fill attribute from generated <Path> in icon component I am able to change the fill via props. .svgo.yml configuration:...
Read more >
Options - SVGR
Keep width and height attributes from the root SVG tag. Removal is guaranteed if dimensions: false , unlike the removeDimensions: true SVGO plugin...
Read more >
Can I clean up unused style attributes? - Beginners' Questions
Is there some way to remove all non-essential attributes, or specifically promote visual style properties to attributes, like fill/stroke?
Read more >
svgo - npm
Plugin Description Default removeDoctype remove doctype declaration enabled removeXMLProcInst remove XML processing instructions enabled removeComments remove comments enabled
Read more >
@innocuous/svgo - npm Package Health Analysis | Snyk
What it can do ; removeOffCanvasPaths, removes elements that are drawn outside of the viewbox, disabled ; removeStyleElement, remove <style> elements, disabled.
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