P
P
Pipop2020-07-31 11:21:16
JavaScript
Pipop, 2020-07-31 11:21:16

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
5f23d417aadb2631456280.png

: config:

{
    test: /\.svg$/,
    loader: 'svg-sprite-loader',
    include: path.resolve(__dirname, 'src/icons/'),
    options: {
         extract: true,
          spriteFilename: 'icons/icons.svg',
        }
   }


And in App.js:

function requireAll(r) {
    r.keys().forEach(r);
}

requireAll(require.context('./icons', true, /\.svg$/));


Tell me, what's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pipop, 2020-08-01
@Pipop

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 question

Ask a Question

731 491 924 answers to any question