refactor(lqip-loader): remove unused palette option (#6992)

This commit is contained in:
Joshua Chen 2022-03-25 10:23:42 +08:00 committed by GitHub
parent 395136a731
commit d3065b8ad2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 469 deletions

View file

@ -22,13 +22,6 @@ export default async function lqipLoader(
}
const callback = this.async();
const imgPath = this.resourcePath;
const config = this.getOptions() ?? {};
config.base64 = 'base64' in config ? config.base64 : true;
// color palette generation is set to false by default
// since it is little bit slower than base64 generation
config.palette = 'palette' in config ? config.palette : false;
let content = contentBuffer.toString('utf8');
const contentIsUrlExport =
/^(?:export default|module.exports =) "data:.*base64,.*/.test(content);
@ -53,24 +46,11 @@ export default async function lqipLoader(
)!.groups!.source!;
}
const outputPromises: [Promise<string> | null, Promise<string[]> | null] = [
config.base64 === true ? lqip.base64(imgPath) : null,
config.palette === true ? lqip.palette(imgPath) : null,
];
try {
const data = await Promise.all(outputPromises);
if (data) {
const [preSrc, palette] = data;
const finalObject = JSON.stringify({src: 'STUB', preSrc, palette});
const result = `module.exports = ${finalObject.replace(
'"STUB"',
source,
)};`;
callback(null, result);
} else {
callback(new Error('ERROR'), undefined);
}
const preSrc = await lqip.base64(imgPath);
const finalObject = JSON.stringify({src: 'STUB', preSrc});
const result = `module.exports = ${finalObject.replace('"STUB"', source)};`;
callback(null, result);
} catch (err) {
console.error(err);
callback(new Error('ERROR'), undefined);