From fd133138e2f6e1248c3ce5e523adb4f378861179 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Fri, 14 Feb 2020 15:51:09 +0000 Subject: [PATCH] fix(@angular-devkit/build-angular): limit CPUs used by terser-webpack-plugin Should help with https://github.com/angular/angular-cli/issues/16860#issuecomment-585751187 --- .../models/webpack-configs/common.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts index 0096c3873e81..dd6c6a0e235d 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts @@ -12,6 +12,7 @@ import { import { tags } from '@angular-devkit/core'; import * as CopyWebpackPlugin from 'copy-webpack-plugin'; import { existsSync } from 'fs'; +import { cpus } from 'os'; import * as path from 'path'; import { RollupOptions } from 'rollup'; import { ScriptTarget } from 'typescript'; @@ -427,10 +428,16 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration { mangle: allowMangle && buildOptions.platform !== 'server' && !differentialLoadingMode, }; + // Use up to 7 CPUs for Terser workers, but no more. + // Some environments, like CircleCI, report a large number of CPUs but trying to use them + // Will cause `Error: Call retries were exceeded` errors. + // https://github.com/webpack-contrib/terser-webpack-plugin/issues/143 + const maxCpus = Math.min(cpus().length, 7); + extraMinimizers.push( new TerserPlugin({ sourceMap: scriptsSourceMap, - parallel: true, + parallel: maxCpus, cache: !cachingDisabled && findCachePath('terser-webpack'), extractComments: false, chunkFilter: (chunk: compilation.Chunk) => @@ -441,7 +448,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration { // They are shared between ES2015 & ES5 outputs so must support ES5. new TerserPlugin({ sourceMap: scriptsSourceMap, - parallel: true, + parallel: maxCpus, cache: !cachingDisabled && findCachePath('terser-webpack'), extractComments: false, chunkFilter: (chunk: compilation.Chunk) =>