-
-
Notifications
You must be signed in to change notification settings - Fork 425
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
Can't set SVGO options #400
Comments
Hey @ThiagoFacchini 👋, |
Use |
Thanks for your suggestion @gregberge, but it didn't work either. Here's how I tried:
I only get Also double checked my svg, which looks like: What else could be causing this annoying issue? |
I don't know it needs to be investigated. |
Extra information: I downgraded the library to 4.3.3 and svgo and svgoConfig options don't work either. |
You should try to investigate it by adding some |
I'm on version # .svgo.yml
plugins:
- removeViewBox: false This works in development mode and does not remove the viewBox attribute from svg, but it removes that attribute during the production mode. Not sure why. 🤔 |
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. // SVG: imported and rendered inline from JS files
svgInline: {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: {
// Only inlining svg loaded from jsx? files
test: /\.jsx?$/,
},
use: [
'babel-loader',
{
loader: '@svgr/webpack',
/*
Using .svgo.yml for now to prevent the removeViewBox issue
*/
options: {
svgoConfig: {
// See: https://github.com/svg/svgo#what-it-can-do
// Important! We need to stick to @svgr/weback v4.3.3 to prevent an issue
// where removeViewBox is not applied (still not fixed in 5.2.0).
plugins: [{
removeViewBox: false,
removeTitle: false,
convertShapeToPath: false,
mergePaths: false,
}],
}
},
},
],
}, |
@kbouchard thanks |
Ok, after some invastigation i found how to make it work. This does not work: const svgoConfig = {
plugins: [
{
convertColors: {
currentColor: true,
},
prefixIds: {
prefix: componentName
}
},
],
}; This works (note each plugin settings must be in its own object) const svgoConfig = {
plugins: [
{
convertColors: {
currentColor: true,
}
}, {
prefixIds: {
prefix: componentName
}
},
],
}; Maybe we could ehance the |
@ghostd thanks for the investigation! Of course we should being able to handle it. Could you (or anyone else) submit a PR please? |
I'm getting This syntax works, but I need to pass options. {
name: 'removeViewBox',
active: false
} All examples I saw are using removeViewBox: {
// options here
} But I can't use this config format because of this error. Is there a documentation on how to pass options to plugins? |
@VityaSchel you should give a look to SVGO documentation. |
I thought I'd finally cracked this problem in my webpack config by breaking the plugins into separate objects like so:
However, after a few builds I (or cache clears?) I noticed my transforms and number lists were being manipulated. I seem to be back in control by using a separate
I prefer to keep all bundling config in a single file where possible, but this seems to be the working option for now. |
This worked for me using svgr({
svgoConfig: {
plugins: [
{
name: 'removeViewBox',
active: false
},
]
}
}), |
It may make sense when SVGO is used standalone. But passing |
🐛 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:
in .svgorc:
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?
The text was updated successfully, but these errors were encountered: