Use svgo to optimize svg file, transformed as string or data-uri or file.
svgo
: SVGO.Options, configuration passed to svgo, see https://github.com/svg/svgo. (ps:datauri
will be ignored.)limit
:number
, when optimized svg file size is larger than limit, will usefallback
option.fallback
:{ loader: string, options: any }
, see above, default fallback isfile-loader
.
npm install inline-svgo-loader --save-dev
{
module: {
rules: [
{
test: /\.(svg)(\?.*)?$/,
loader: 'inline-svgo-loader',
options: {
svgo: {},
limit: 4 * 1024,
fallback: {
loader: 'file-loader',
options: { name: '[name].svg' }
}
}
}
]
}
}
Just append datauri
query param to svg file path to support data url(data:image/svg+xml,%3csvg...
, Not base64).
eg: in css background-image: url('assets/some.svg?datauri')
.
This loader will ignore datauri
in option svgo
.