Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return Promise.all(map(compilation.assets, (asset, filename) => throttle(async () => {
const assetSource = asset.source()
// Skip the image if it's not a match for the regex
if (testFile(filename, testRegexes) && testFileSize(assetSource, minFileSize, maxFileSize)) {
// Optimize the asset's source
const optimizedImageBuffer = await optimizeImage(assetSource, imageminOptions)
// Then write the optimized version back to the asset object as a "raw source"
compilation.assets[filename] = new RawSource(optimizedImageBuffer)
}
})))
}
filename: fileOutput,
sourceMap: Boolean(compiler.options.devtool),
});
if (map && sourceMap) {
const consumerMap = await new SourceMapConsumer(sourceMap);
map.applySourceMap(consumerMap, fileOutput);
}
if (!map) {
map = sourceMap;
}
compilation.assets[fileOutput] = map
? new SourceMapSource(css, fileOutput, map.toJSON ? map.toJSON() : map)
: new RawSource(css);
} catch (err) {
const prefix = `${file} from CssoWebpackPlugin\n`;
const { message, parseError, stack } = err;
let error = `${message} ${stack}`;
if (parseError) {
error = `${message} [${file}:${parseError.line}:${parseError.column}]`;
}
compilation.errors.push(new Error(`${prefix}${error}`));
}
}),
)),