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

How to handle srcset attributes? #148

Open
mimamuh opened this issue Nov 23, 2017 · 2 comments · May be fixed by #188 or #223
Open

How to handle srcset attributes? #148

mimamuh opened this issue Nov 23, 2017 · 2 comments · May be fixed by #188 or #223

Comments

@mimamuh
Copy link

mimamuh commented Nov 23, 2017

Hi,

I'm using this loader to combine html sources together. I tried to figure out how I could hanlde the srcset attribute of a picture element properly.

I want to auto-resolve the path within the srcset the same way like it works with src on a regular img tag.

For example with the html-loader I can pass attrs which will be used to resolved the urls:

loader: 'html-loader',
options: {
    // which tag:attribute combination should be processed
    attrs: [':data-src', 'img:src', 'img:srcset', 'source:srcset'],
}

Is there a similiar way with the handlebars-loader? I currently use the inlineRequires: '/img/' option of the handlebars-loader and it works for normal src attributes, but not with srcset attributes.

So I tried to build a workaround, first using the handlebars-loader without the inlineRequires and pipe the output to the html-loader but it doesn't seem to work because of the output the handlebars-loader is producing. Or is there some way I've missed?

Thx!

@orian
Copy link

orian commented Mar 13, 2019

Not solving your issue, but <img src> tag:

{
                test: /\.mst(.html)?/,
                use: [
                    {
                        loader: "handlebars-loader",
                        options: {
                            extensions: ['.mst.html', '.mst'],
                            knownHelpers: ['math', 'lt'],
                        }
                    },
                    {loader: 'extract-loader'},
                    {
                        loader: 'html-loader',
                        options: {
                            attrs: [
                                ':data-src',
                                'img:src'
                            ],
                            options: {
                                minimize: true
                            }
                        }
                    }
                ]
            }
        ]

@mmousawy mmousawy linked a pull request Sep 30, 2019 that will close this issue
@gswierczynski
Copy link

Is there a solution to this?
I see PR but it did not end up being merged.
The extract-loader does not seem to work with webpack 5.
Am I missing something?

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