Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reduce memory usage #145

Merged
merged 1 commit into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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