Comments (6)
This webpack-config fixed things for me:
rules: [
{
test: /\.svg$/,
use: [
'babel-loader',
{
loader: 'svgr/lib/webpack',
options: {
icon: true,
},
},
],
},
]
from svgr.
@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.
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.
Thank you, I precised it in documentation!
from svgr.
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.
@etienne got it thanks
from svgr.
Related Issues (20)
- overwriting dimensions HOT 1
- Website not working on Arc browser HOT 4
- Does the current project support the use of Vue2 or Vue3?
- fallback title is not working HOT 1
- Using props on SVGR components dynamically-imported with webpack
- exportType still doesn't work with rollupjs ?! HOT 1
- Unable to resolve 'path'
- White screen of death (React error) on the website HOT 1
- Generate d.ts per svg file
- Svgr trying to convert attributes fills in to style
- provide example on how to manipulate custom template props
- Command line tool outputting to file with binary character appended to the beginning and fails to compile
- Support ESM for templates
- How to use jsx elements in template
- SVGR does not inline the transform-origin CSS property correctly HOT 3
- Example `rollup.config.js` in README is incomplete
- How to preserve role from template?
- Warning: The tag <SvgrURL> is unrecognized in this browser
- @svgr/hast-util-to-babel-ast erroneously treats semicolons in XML entities as style delimiters HOT 1
- CSP nonce
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from svgr.