diff --git a/src/TaskRunner.js b/src/TaskRunner.js index 25e0713f..e412ce29 100644 --- a/src/TaskRunner.js +++ b/src/TaskRunner.js @@ -41,10 +41,6 @@ export default class TaskRunner { } async run(tasks) { - if (tasks.length === 0) { - return Promise.resolve([]); - } - if (this.numberWorkers > 1 && tasks.length > 1) { this.worker = new Worker(workerPath, { numWorkers: this.numberWorkers }); } diff --git a/src/index.js b/src/index.js index a9b17a0a..353a62d4 100644 --- a/src/index.js +++ b/src/index.js @@ -170,11 +170,6 @@ class TerserPlugin { }; const optimizeFn = async (compilation, chunks) => { - const taskRunner = new TaskRunner({ - cache: this.options.cache, - parallel: this.options.parallel, - }); - const processedAssets = new WeakSet(); const tasks = []; @@ -267,9 +262,18 @@ class TerserPlugin { } }); - const completedTasks = await taskRunner.run(tasks); + let completedTasks = []; + + if (tasks.length > 0) { + const taskRunner = new TaskRunner({ + cache: this.options.cache, + parallel: this.options.parallel, + }); + + completedTasks = await taskRunner.run(tasks); - await taskRunner.exit(); + await taskRunner.exit(); + } completedTasks.forEach((completedTask, index) => { const { file, input, inputSourceMap, commentsFile } = tasks[index];