Answer the question
In order to leave comments, you need to log in
How to properly assemble svg sprite using webpack?
I work with Wepback for the first time, I follow this article: https://sathyalog.wordpress.com/2019/04/04/convert...
Now I have icons.svg generated, but at the same time other svg files too
: config:
{
test: /\.svg$/,
loader: 'svg-sprite-loader',
include: path.resolve(__dirname, 'src/icons/'),
options: {
extract: true,
spriteFilename: 'icons/icons.svg',
}
}
function requireAll(r) {
r.keys().forEach(r);
}
requireAll(require.context('./icons', true, /\.svg$/));
Answer the question
In order to leave comments, you need to log in
Should have slept first.
The above example correctly generates the sprite, the rest of the files in the dist root are the result of incorrect image configuration. Resolved like this:
{
test: /\.(png|jpg|svg|webp|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'images/'
}
}
]
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question