Disable stripping viewBox #735
-
I must be looking in all the wrong places; sorry if so. How can I disable stripping the viewBox attribute from SVGs? Relatedly, is there a way to add a viewBox if it doesn't already exist? (i.e. turn |
Beta Was this translation helpful? Give feedback.
Replies: 18 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
// in .svgrrc.js
module.exports = {
svgoConfig: {
plugins: {
removeViewBox: false
}
}
}; |
Beta Was this translation helpful? Give feedback.
-
Thanks, that got me on the right lines. That didn't work for me (I may have made a typo) but I saw in the options I can do a YAML file instead. I ended up writing a file plugins:
- removeViewBox: false |
Beta Was this translation helpful? Give feedback.
-
is there a way to specify this option with |
Beta Was this translation helpful? Give feedback.
-
okay, if anyone runs into the same thing. i've managed to make it work with webpack config like so: {
test: /(icons|images)\/.*?.svg$/,
use: [{
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: {
removeViewBox: false
}
}
}
}, 'file-loader']
}``` |
Beta Was this translation helpful? Give feedback.
-
Any idea if there's a way to do that in a `require` statement, i.e. with no
special Webpack configuration?
|
Beta Was this translation helpful? Give feedback.
-
If you're configuring/disabling several
|
Beta Was this translation helpful? Give feedback.
-
Keeping the viewBox attribute really should be the default.. |
Beta Was this translation helpful? Give feedback.
-
@vlinder you should submit a PR to SVGO. |
Beta Was this translation helpful? Give feedback.
-
The SVGO option in Example
|
Beta Was this translation helpful? Give feedback.
-
Saved my day. .svgrrc didn't work for me since in my case the issue was in the rollup bundle plugin. Adding a .svgorc config fixed it. |
Beta Was this translation helpful? Give feedback.
-
if use rollup.config, you can create .svgarc file |
Beta Was this translation helpful? Give feedback.
-
This is what worked for me:
|
Beta Was this translation helpful? Give feedback.
-
This worked like charm, thanks for this answer. |
Beta Was this translation helpful? Give feedback.
-
For anyone like me that was using
|
Beta Was this translation helpful? Give feedback.
-
I'm using
|
Beta Was this translation helpful? Give feedback.
-
for nextjs14 && @svgr/[email protected],
|
Beta Was this translation helpful? Give feedback.
-
If you want to keep it all inside the vite config import { defineConfig } from 'vite';
import svgr from '@svgr/rollup';
export default defineConfig({
plugins: [
svgr({
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
},
},
},
],
},
}),
],
}); |
Beta Was this translation helpful? Give feedback.
This is what worked for me:
https://stackoverflow.com/a/70360615/1110814