Skip to content

Commit

Permalink
fix: reduce memory usage (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Sep 6, 2019
1 parent 42a0f9c commit 815e533
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/TaskRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
18 changes: 11 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 815e533

Please sign in to comment.