Last active
October 6, 2019 13:53
-
-
Save kilgarenone/08196cd04d9c4d26a546f48b53bc2816 to your computer and use it in GitHub Desktop.
svg webpack loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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