JetBrains / svg-sprite-loader

Webpack loader for creating SVG sprites.
MIT License
2.01k stars 272 forks source link

sprite loader doesn't work with multiple loaders (having multiple in- and outputs): all svg's go into first sprite #438

Open bencresty opened 3 years ago

bencresty commented 3 years ago

Do you want to request a feature, report a bug or ask a question? Report a bug

What is the current behavior? When adding the loader multiple times on different in- and outputs all sprites get added to the first file and the second sprite file isn't created.

What is the expected behavior? All sprites from source A rendered to sprite A and all sprites from source B rendered to sprite B.

If the current behavior is a bug, please provide the steps to reproduce, at least part of webpack config with loader configuration and piece of your code.

Webpack config part on svg-sprite-loader:

const SVGSpriteLoaderPlugin = require('svg-sprite-loader/plugin');

// ...

const svgSprites = ['sprite-a', 'sprite-b'];
for (let i = 0; i < svgSprites.length; i++) {
    const folderName = svgSprites[i];
    const spritesSource = path.resolve(paths.src, `assets/svg-sprites/${folderName}`);
    const relSpriteFilename = `assets/img/${folderName}.svg`;

    config.module.rules.push({
        test: /\.(svg)(\?[a-z0-9=.]+)?$/,
        include: spritesSource,
        use: [{
            loader: 'svg-sprite-loader',
            options: {
                extract: true,
                spriteFilename: relSpriteFilename,
            },
        }],
    });
}

// ...

config.plugins.push(new SVGSpriteLoaderPlugin({ plainSprite: false }));

// ...

Please tell us about your environment: