Skip to content

Instantly share code, notes, and snippets.

@kilgarenone
Last active October 6, 2019 13:53
Show Gist options
  • Save kilgarenone/08196cd04d9c4d26a546f48b53bc2816 to your computer and use it in GitHub Desktop.
Save kilgarenone/08196cd04d9c4d26a546f48b53bc2816 to your computer and use it in GitHub Desktop.
svg webpack loader
module.exports = {
module: {
rules: [{
test: /\.svg$/,
use: [
// encode < 4KB bytes svg to utf-8 data-uri for smaller size.
// Fallback to file-loader for > 4KB files.
{
loader: "svg-url-loader",
options: {
// Remove the quotes from the url
noquotes: true,
stripdeclarations: true,
// Inline files smaller than 4 kB
limit: 4 * 1024,
name: `img/[name].[hash].[ext]`
}
},
// optimizes/cleanup svg files output from sketch, photoshop etc.
{
loader: "img-loader",
options: {
plugins: [
require("imagemin-svgo")({
plugins: [{ removeTitle: true }, { convertPathData: false }]
})
]
}
}
]
}]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment