svg-sprite-loader icon indicating copy to clipboard operation
svg-sprite-loader copied to clipboard

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

Open MarmaladeKnight opened this issue 2 years ago • 1 comments

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:

  • Node.js version: 16.15.1
  • webpack version: 5.44.0
  • svg-sprite-loader version: ^6.0.6
  • OS type & version: Windows

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

MarmaladeKnight avatar Jul 11 '22 19:07 MarmaladeKnight

for me too

artemkliaus avatar Jan 25 '23 14:01 artemkliaus