Skip to content

Commit fd13313

Browse files
filipesilvaKeen Yee Liau
authored and
Keen Yee Liau
committed
fix(@angular-devkit/build-angular): limit CPUs used by terser-webpack-plugin
Should help with #16860 (comment)
1 parent 9188467 commit fd13313

File tree

1 file changed

+9
-2
lines changed
  • packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs

1 file changed

+9
-2
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { tags } from '@angular-devkit/core';
1313
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
1414
import { existsSync } from 'fs';
15+
import { cpus } from 'os';
1516
import * as path from 'path';
1617
import { RollupOptions } from 'rollup';
1718
import { ScriptTarget } from 'typescript';
@@ -427,10 +428,16 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
427428
mangle: allowMangle && buildOptions.platform !== 'server' && !differentialLoadingMode,
428429
};
429430

431+
// Use up to 7 CPUs for Terser workers, but no more.
432+
// Some environments, like CircleCI, report a large number of CPUs but trying to use them
433+
// Will cause `Error: Call retries were exceeded` errors.
434+
// https://github.com/webpack-contrib/terser-webpack-plugin/issues/143
435+
const maxCpus = Math.min(cpus().length, 7);
436+
430437
extraMinimizers.push(
431438
new TerserPlugin({
432439
sourceMap: scriptsSourceMap,
433-
parallel: true,
440+
parallel: maxCpus,
434441
cache: !cachingDisabled && findCachePath('terser-webpack'),
435442
extractComments: false,
436443
chunkFilter: (chunk: compilation.Chunk) =>
@@ -441,7 +448,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
441448
// They are shared between ES2015 & ES5 outputs so must support ES5.
442449
new TerserPlugin({
443450
sourceMap: scriptsSourceMap,
444-
parallel: true,
451+
parallel: maxCpus,
445452
cache: !cachingDisabled && findCachePath('terser-webpack'),
446453
extractComments: false,
447454
chunkFilter: (chunk: compilation.Chunk) =>

0 commit comments

Comments
 (0)