MinifyWorker: Promisify `compressCSS`

pull/5284/head
Richard Hansen 2021-11-15 03:11:54 -05:00
parent c94906f1f8
commit 98f0e931fe
1 changed files with 5 additions and 9 deletions

View File

@ -10,25 +10,21 @@ const Threads = require('threads');
const compressJS = (content) => Terser.minify(content);
const compressCSS = (filename, ROOT_DIR) => new Promise((res, rej) => {
const compressCSS = async (filename, ROOT_DIR) => {
try {
const absPath = path.resolve(ROOT_DIR, filename);
const basePath = path.dirname(absPath);
new CleanCSS({
const output = await new CleanCSS({
rebase: true,
rebaseTo: basePath,
}).minify([absPath], (errors, minified) => {
if (errors) return rej(errors);
return res(minified.styles);
});
}).minify([absPath]);
return output.styles;
} catch (error) {
// on error, just yield the un-minified original, but write a log message
console.error(`Unexpected error minifying ${filename} (${absPath}): ${error}`);
callback(null, content);
}
});
};
Threads.expose({
compressJS,