From d65ac2d01109d14c9e7e0aca472b7234a6e760cb Mon Sep 17 00:00:00 2001 From: Murtada al Mousawy Date: Mon, 30 Sep 2019 15:57:20 +0200 Subject: [PATCH] Added inlineRequires handling for srcset --- index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index.js b/index.js index b02466800..d85649e4f 100644 --- a/index.js +++ b/index.js @@ -127,6 +127,27 @@ module.exports = function(source) { if (str.indexOf && str.indexOf('"') === 0) { var replacements = findNestedRequires(str, inlineRequires); str = fastreplace(str, replacements, function (match) { + + if (match.indexOf(',') > -1) { + // Handle srcset + const srcset = match.split(','); + + let srcsetParts = []; + + srcset.forEach(src => { + const fileSrcParts = src.trim().split(' '); + const fileSrc = fileSrcParts[0]; + const fileStuffix = fileSrcParts[1] + ? ` ${fileSrcParts[1]}` + : ''; + srcsetParts.push(`" + require('${loaderUtils.stringifyRequest(loaderApi, fileSrc)}') + "${fileStuffix}`); + }); + + const returnString = srcsetParts.join(','); + + return returnString; + } + return "\" + require(" + loaderUtils.stringifyRequest(loaderApi, match) + ") + \""; }); }