fix: handle content from loaders
This commit is contained in:
parent
420e8b6815
commit
eaaccf9d6c
|
@ -102,6 +102,13 @@ const encodeDataUri = (encoding, source) => {
|
|||
return encodedContent;
|
||||
};
|
||||
|
||||
const decodeDataUriContent = (encoding, content) => {
|
||||
const isBase64 = encoding === "base64";
|
||||
return isBase64
|
||||
? Buffer.from(content, "base64")
|
||||
: Buffer.from(decodeURIComponent(content), "ascii");
|
||||
};
|
||||
|
||||
const JS_TYPES = new Set(["javascript"]);
|
||||
const JS_AND_ASSET_TYPES = new Set(["javascript", "asset"]);
|
||||
|
||||
|
@ -187,30 +194,12 @@ class AssetGenerator extends Generator {
|
|||
|
||||
let encodedContent;
|
||||
|
||||
const decodeDataURI = uri => {
|
||||
const match = URIRegEx.exec(uri);
|
||||
if (!match) return null;
|
||||
|
||||
const isBase64 = match[3];
|
||||
const body = match[4];
|
||||
return isBase64
|
||||
? Buffer.from(body, "base64")
|
||||
: Buffer.from(decodeURIComponent(body), "ascii");
|
||||
};
|
||||
|
||||
const decodeDataUriContent = (encoding, content) => {
|
||||
const isBase64 = encoding === "base64";
|
||||
return isBase64
|
||||
? Buffer.from(content, "base64")
|
||||
: Buffer.from(decodeURIComponent(content), "ascii");
|
||||
};
|
||||
|
||||
if (
|
||||
module.resourceResolveData &&
|
||||
module.resourceResolveData.encoding === encoding &&
|
||||
decodeDataUriContent(
|
||||
module.resourceResolveData.encoding,
|
||||
module.resourceResolveData.encodedContent,
|
||||
module.resourceResolveData.encodedContent
|
||||
).equals(originalSource.buffer())
|
||||
) {
|
||||
encodedContent = module.resourceResolveData.encodedContent;
|
||||
|
|
Loading…
Reference in New Issue