将选项从 svgr/webpack 传递给内置的 svgo [英] Pass options to the builtin svgo from svgr/webpack

查看:73
本文介绍了将选项从 svgr/webpack 传递给内置的 svgo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 svgo 选项传递给 svgr/webpack 加载器?我想删除宽度 &高度属性并保留视图框,默认情况下它会删除这些.

Is there an option to pass in svgo options to the svgr/webpack loader ? I want to remove the width & height attributes and keep the viewbox, by default it removes those.

{
    test: /\.svg$/,
    use: ['@svgr/webpack'],
    options : {
    svgo: { // Something like this ?
        mergePaths: false,
        removeViewbox: false,
        removeAttrs: true,
    }}

},

推荐答案

我找不到通过 svgr 将参数传递到 svgo 的方法,所以我切换到 react-svg-loader如何实现:

I could not find a way of passing arguments through svgr to svgo so I switched to react-svg-loader which has documentation on how to achieve that :

{
    test: /\.svg$/,
    use: [
        'babel-loader',
        {
            loader: 'react-svg-loader',
            options: {
                svgo: {
                    plugins: [{ removeDimensions: true, removeViewBox: false }],
                    floatPrecision: 2,
                },
            },
        },
    ],
},

这篇关于将选项从 svgr/webpack 传递给内置的 svgo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆