Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Should additional SVGO plugins work? #274

Open
OttoLaitinen opened this issue Jun 20, 2023 · 1 comment
Open

[Question] Should additional SVGO plugins work? #274

OttoLaitinen opened this issue Jun 20, 2023 · 1 comment

Comments

@OttoLaitinen
Copy link

OttoLaitinen commented Jun 20, 2023

I have tried to add the SVGO plugin convertStyleToAttrs to be able to use replaceAttrValues as the replacement only works for attributes and not for inline styles.

This is my SVG code:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 26.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<style type="text/css">
	.st0{fill-rule:evenodd;clip-rule:evenodd;fill:#000000;}
</style>
<path class="st0" d="M20.7,19.3c0.4,0.4,0.4,1,0,1.4s-1,0.4-1.4,0L12,13.4l-7.3,7.3c-0.4,0.4-1,0.4-1.4,0c-0.4-0.4-0.4-1,0-1.4
	l7.3-7.3L3.3,4.7c-0.4-0.4-0.4-1,0-1.4c0.4-0.4,1-0.4,1.4,0l7.3,7.3l7.3-7.3c0.4-0.4,1-0.4,1.4,0c0.4,0.4,0.4,1,0,1.4L13.4,12
	L20.7,19.3z"/>
</svg>

And this is my svgrrc.js:

module.exports = {
  replaceAttrValues: {
    "#000000": "currentColor",
  },
  svgo: true,
  svgoConfig: {
    plugins: ["convertStyleToAttrs"],
  },
};

For some reason, the additional plugin doesn't seem to be registered because when I'm looking at the non source mapped JS code the <style> tag has been changed to inline styles (through the use of inlineStyles SVGO -plugin which is apparently default for react-native-svg-transformer) but the inlineStyles are not changed to attributes.

So my question is that is it possible to use additional SVGO plugins through SVGR-config with this package? I think my code is correct as it is working in the SVGR-playground (the link has the same config but the SVG code has to be copied from here to there).

Great if someone is able to help 🙏🏻

@b3nb5n
Copy link

b3nb5n commented Aug 12, 2023

I'm also having this issue, I've confirmed my config works using the svgr playground and this svg

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 26 26" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;"><path d="M13.02,1c6.634,0 12.02,5.386 12.02,12.02c-0,6.634 -5.386,12.02 -12.02,12.02c-6.634,-0 -12.02,-5.386 -12.02,-12.02c0,-6.634 5.386,-12.02 12.02,-12.02Zm-2.18,7.984c-0.155,-0.095 -0.348,-0.098 -0.506,-0.01c-0.158,0.089 -0.255,0.255 -0.255,0.436l-0,7.219c-0,0.181 0.097,0.348 0.255,0.436c0.158,0.089 0.351,0.085 0.506,-0.009l5.895,-3.61c0.149,-0.091 0.239,-0.252 0.239,-0.426c0,-0.174 -0.09,-0.336 -0.239,-0.427l-5.895,-3.609Z" style="fill:#f00;"/></svg>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants