Skip to content

Images aren't being loaded using "data-srcset", unable to define data-srcset on <source> #316

@GuillermoCasanova

Description

@GuillermoCasanova
  • Operating System: Mac OS
  • Node Version: 12.9.0
  • NPM Version: 6.10.2
  • webpack Version: 4.41.5
  • html-loader Version: 1.2.1

Expected Behavior

Images using data-srcset on tag for lazysizes should work if including data-srcset in the list of attributes that html-loader checks for.

Actual Behavior

Images aren't being loaded. Compilation happens but when the image is fetched by srcset it can't find it in the assets folder.

Also unable to define it like so, as it returns invalid, saying that data-srcset is not a valid tag on "source":

	{
			        			tag: 'source', 
			        			attribute: 'data-srcset',
			        			type: 'srcset'
			        		}

Code



<picture>
    <source  media="--medium" data-srcset="../../../assets/envelope-01-opti-2.png">
   <img data-src="../../../assets/envelope-01-opti.png" alt="" 
class="lazyload">
</picture>


  config.module = {
		rules: [
				{
					test: /\.js$/,
					exclude: /node_modules/, 
					use: {
						loader: 'babel-loader'
					}
				},	
	      {
	        test: /\.html$/,
	        use: [
	          {
	            loader: "html-loader",
	           	options: { 
			        	attributes: {
			        		list: [
					       {
			        			tag: 'source', 
			        			attribute: 'src-set',
			        			type: 'srcset'
			        		},
			        		{
			        			tag: 'img', 
			        			attribute: 'data-src',
			        			type: 'src'
			        		},
			        		{
			        			tag: 'img', 
			        			attribute: 'src',
			        			type: 'src'
			        		},
			        		{
			        			tag: 'source', 
			        			attribute: 'srcset',
			        			type: 'srcset'
			        		},
			        		{
			        			tag: 'img', 
			        			attribute: 'data-srcset',
			        			type: 'srcset'
			        		}
				        	]
           			}
	           	}
	          }
	        ]
	      },
				{
					test: /\.scss$/,
					use: [
						MiniCssExtractPlugin.loader,
						//'postcss-loader',
						'css-loader',
						'sass-loader',
						]
				},
	      { 
	        test: /\.css$/,
	        use: [ 'style-loader', 
	        	{loader: 'css-loader',
	        	options: {
	        		url: true 
	        	} 
	        }
	        ]
	      },
        {
      	 test: /\.(png|svg|jpg|gif|msi|woff|woff2)$/,
      	 use: {
       	 loader: 'file-loader', 
       	 options: {
       		name: "assets/[name].[contenthash].[ext]",
          esModule: false,
          attrs: ['img:src', 'source:srcset', "img:data-src", "source:data-srcset"]
       	}
       }
      }
		]
	}; 

How Do We Reproduce?

Install htm-loader and file-loader with webpack. Create a picture tag inside an html file with img and source inside of it. Use data-srcset in the source tag for lazysizes to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions