JetBrains / svg-sprite-loader

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

Unable to modify spriteFilename if loader rule has resourceQuery while using SpriteLoaderPlugin #492

Open MarmaladeKnight opened 2 years ago

MarmaladeKnight commented 2 years ago

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

What is the current behavior? Always get sprite.svg filename

What is the expected behavior? Loader gets filename from options and plugin uses it

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.

{
    test: /\.svg$/,
    resourceQuery: /^$/,
    use: [
        {
            loader: "url-loader",
            options: {
                generator: (content) =>
                    svgToMiniDataURI(content.toString()),
                esModule: false,
            },
        },
        {
            loader: "svgo-loader",
        },
    ],
},
{
    test: /\.svg$/,
    resourceQuery: /\?symbol$/,
    use: [
        {
            loader: "svg-sprite-loader",
            options: {
                extract: true,
                spriteFilename: 'sprite-[hash:6].svg',
                outputFolder: outputFolder,
                symbolId: (filePath) => {
                    const dirName = path
                        .dirname(filePath)
                        .split(path.sep)
                        .slice(-1);
                    return `${dirName}--${path.basename(
                        filePath,
                        ".svg",
                    )}`;
                },
            },
        },
        {
            loader: "svgo-loader",
        },
    ]
},

Please tell us about your environment:

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

As I debug problem is in this line https://github.com/JetBrains/svg-sprite-loader/blob/051b82e48db26e1bb234ab9ba5f3ea9fdbc3b9db/lib/utils/get-matched-rule-5.js#L46

It works only for the first rule and thats why several lines later plugin can`t find the rule for itself and sets it as empty object

...And little bit later in this condition plugin use default sprite name https://github.com/JetBrains/svg-sprite-loader/blob/4a3d105491aa88400734e1cdaba80da1657e8efa/lib/utils/mapped-list.js#L91

artemkliaus commented 1 year ago

for me too