svgr: Can't set SVGO options
🐛 Bug Report
I need basically need to keep the svg viewBox when using @svgr/webpack.
I tried every piece of documentation I found spread among web pages and tickets previously opened in git.
svgr/webpack version: 5.1.0 webpack version: 4.29.6
To Reproduce
Configurations I tried:
webpack config file:
{
test: /\.svg$/,
use: [{
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: [{
removeViewBox: false
}]
}
}
}, 'file-loader']
},
in .svgorc:
plugins:
- removeViewBox: false
with the webpack config file I tried inside my application:
import svgfileurl , { ReactComponent as svgFile } from 'whatevever.svg'
both svgfileurl and svgFile return a function which returns a reactComponent
Expected behavior
For the viewBox attribute to be preserved
Any ideas?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 16 (5 by maintainers)
Links to this issue
Commits related to this issue
- fix(svgo): support any SVGO config format Fixes #400 — committed to gregberge/svgr by gregberge 4 years ago
- fix(svgo): support any SVGO config format Fixes #400 — committed to gregberge/svgr by gregberge 4 years ago
- fix(svgo): support any SVGO config format Fixes #400 — committed to gregberge/svgr by gregberge 4 years ago
- fix(svgo): support any SVGO config format Fixes #400 — committed to gregberge/svgr by gregberge 4 years ago
- fix(svgo): support any SVGO config format Fixes #400 — committed to gregberge/svgr by gregberge 4 years ago
- fix(svgo): support any SVGO config format (#412) Fixes #400 — committed to gregberge/svgr by gregberge 4 years ago
@VityaSchel you should give a look to SVGO documentation.
Use
svgoin option instead ofsvgoConfig.Hey guys, I just went through the same issue on v5.2.0 . After trying a lot of things, nothing worked.
So I downgraded to 4.3.3 , using the config below and it’s working for me now.
Extra information:
I downgraded the library to 4.3.3 and svgo and svgoConfig options don’t work either.
I don’t know it needs to be investigated.
Thanks for your suggestion @gregberge, but it didn’t work either.
Here’s how I tried:
I only get
<svg>in the dom.Also double checked my svg, which looks like:
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26.82 42.81">What else could be causing this annoying issue?
I’m getting
Plugin name should be specifiederrorThis syntax works, but I need to pass options.
All examples I saw are using
But I can’t use this config format because of this error. Is there a documentation on how to pass options to plugins?
Ok, after some invastigation i found how to make it work.
This does not work:
This works (note each plugin settings must be in its own object)
Maybe we could ehance the
extendPluginsfunction to handle this.