Svgr: Preserving viewBox

Created on 15 Nov 2017  路  5Comments  路  Source: gregberge/svgr

Hi,

First of all, thank you for this amazing library, it is great!

With version 1.0.0, viewBox is dropped. In my case I have some illustrations that I inline, they are not icons but I still need viewBox to scale them.

I would be happy to contribute and help, but in order to understand where you come from: what is the rationale behind removing viewBox for "non-icons"?

Most helpful comment

For future googlers (like me). It seems the information in this issue is outdated, viewbox settings are now delegated to the svgoConfig. See https://github.com/smooth-code/svgr/issues/142

Webpack snippet:

{
        test: /(icons|images)\/.*?.svg$/,
        use: [{
          loader: '@svgr/webpack',
          options: {
            svgoConfig: {
              plugins: {
                removeViewBox: false
              }
            }
          }
        }, 'file-loader']
      }

All 5 comments

Hi, after #17 I think adding an option 芦聽viewBox聽禄 and defaulting it to true is the best thing. I think viewBox doesn鈥檛 add a lot of data and give ability to resize, it is pretty common with SVG. @troch feel free to make a PR, else I will do it as soon as I have a moment.

For future googlers (like me). It seems the information in this issue is outdated, viewbox settings are now delegated to the svgoConfig. See https://github.com/smooth-code/svgr/issues/142

Webpack snippet:

{
        test: /(icons|images)\/.*?.svg$/,
        use: [{
          loader: '@svgr/webpack',
          options: {
            svgoConfig: {
              plugins: {
                removeViewBox: false
              }
            }
          }
        }, 'file-loader']
      }

@edorivai yes you are right, viewBox is svgo job!

Note, that in order to work now { removeViewBox: false } should be passed at array:

{
    test: /(icons|images)\/.*?.svg$/,
    use: [{
        loader: '@svgr/webpack',
        options: {
            svgoConfig: {
                plugins: [{removeViewBox: false}]
            }
        }
    }, 'file-loader']
}

Hi,

How to handle this in @svgr/rollup, I mean how to write this config in rollup

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smashercosmo picture smashercosmo  路  3Comments

Kosai106 picture Kosai106  路  4Comments

chloesun picture chloesun  路  6Comments

runeh picture runeh  路  4Comments

AskAlice picture AskAlice  路  3Comments