Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MarmaladeKnight opened this issue Jul 11, 2022 · 1 comment

Comments

@MarmaladeKnight
Copy link

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

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

let spriteFilename = rule.spriteFilename || loaderDefaults.spriteFilename;

@MarmaladeKnight MarmaladeKnight changed the title Unable to modify change spriteFilename if loader rule has resourceQuery while using SpriteLoaderPlugin Unable to modify spriteFilename if loader rule has resourceQuery while using SpriteLoaderPlugin Jul 11, 2022
@artemkliaus
Copy link

for me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants