Coder Social home page Coder Social logo

Comments (6)

luhmann avatar luhmann commented on July 28, 2024

This webpack-config fixed things for me:

rules: [
        {
          test: /\.svg$/,
          use: [
            'babel-loader',
            {
              loader: 'svgr/lib/webpack',
              options: {
                icon: true,
              },
            },
        ],
    },
]

from svgr.

gregberge avatar gregberge commented on July 28, 2024

@luhmann in fact, except for icons I think we do not need viewBox. If it was a problem for you, I could add an option viewBox. What do you think?

from svgr.

luhmann avatar luhmann commented on July 28, 2024

The icon-setting actually works perfectly fine for me and is "correct" as the SVGs I turn into components are icons. I just thought that it might be a cool to highlight the icon-config in the CHANGELOG or in the README for people who encounter broken icons when upgrading to version 1.0.0, because SVGGO now removes the viewBox were it deems it to be safe.

The docs only say this about icon "Remove title and replace SVG "width" and "height" value by "1em"", but when you look at the code it actually also disables the svggo removeViewBox-plugin, which helped me in this case.

If you want my opinion then I think if you change the API of svgr it would actually be more beneficial to expose the ability to pass an svggo customConfig into svgr, because that should solve every need people might have that is within the capabilities of svggo. Of course I cannot judge if that might have a huge impact or might cause a lot of support-requests.

As a side-note:
I actually would have assumed that more people would run into issues with removed viewBoxes. If you have an original svg like this:

<svg width="24" height="24" viewBox="0 0 24 24"><!--- svg code assuming a viewBox of 24 24 --></svg>

SVGGO will look at this and because viewBox and width/height are equal will remove the viewBox. If someone then uses the wrapped svg in react in a way that width and height on the svg are replaced with other values, then I believe it would always look broken?

But maybe I am the only one doing that 😉

Thanks for a great tool! I am happy with the solution I arrived at, close this if you like.

from svgr.

gregberge avatar gregberge commented on July 28, 2024

Thank you, I precised it in documentation!

from svgr.

etienne avatar etienne commented on July 28, 2024

I have the same issue; in my case, the icon option does not quite solve the problem because I don't want the width and height to be changed to 1em.

I agree with @luhmann's suggestion (allowing custom configuration of SVGO), but in my use case adding a viewBox option (that defaults to false) would be good enough. Is that something that could be considered for inclusion in a future release?

from svgr.

gregberge avatar gregberge commented on July 28, 2024

@etienne got it thanks

from svgr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.