lint: src/node/utils/MinifyWorker.js

This commit is contained in:
John McLear 2021-01-21 21:06:52 +00:00 committed by Richard Hansen
parent b5e04d867e
commit b11ba23208

View file

@ -1,3 +1,4 @@
'use strict';
/** /**
* Worker thread to minify JS & CSS files out of the main NodeJS thread * Worker thread to minify JS & CSS files out of the main NodeJS thread
*/ */
@ -7,12 +8,9 @@ const Terser = require('terser');
const path = require('path'); const path = require('path');
const Threads = require('threads'); const Threads = require('threads');
function compressJS(content) { const compressJS = (content) => Terser.minify(content);
return Terser.minify(content);
}
function compressCSS(filename, ROOT_DIR) { const compressCSS = (filename, ROOT_DIR) => new Promise((res, rej) => {
return new Promise((res, rej) => {
try { try {
const absPath = path.join(ROOT_DIR, filename); const absPath = path.join(ROOT_DIR, filename);
@ -56,8 +54,7 @@ function compressCSS(filename, ROOT_DIR) {
console.error(`Unexpected error minifying ${filename} (${absPath}): ${error}`); console.error(`Unexpected error minifying ${filename} (${absPath}): ${error}`);
callback(null, content); callback(null, content);
} }
}); });
}
Threads.expose({ Threads.expose({
compressJS, compressJS,