@@ -12,6 +12,7 @@ import {
12
12
import { tags } from '@angular-devkit/core' ;
13
13
import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
14
14
import { existsSync } from 'fs' ;
15
+ import { cpus } from 'os' ;
15
16
import * as path from 'path' ;
16
17
import { RollupOptions } from 'rollup' ;
17
18
import { ScriptTarget } from 'typescript' ;
@@ -427,10 +428,16 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
427
428
mangle : allowMangle && buildOptions . platform !== 'server' && ! differentialLoadingMode ,
428
429
} ;
429
430
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
+
430
437
extraMinimizers . push (
431
438
new TerserPlugin ( {
432
439
sourceMap : scriptsSourceMap ,
433
- parallel : true ,
440
+ parallel : maxCpus ,
434
441
cache : ! cachingDisabled && findCachePath ( 'terser-webpack' ) ,
435
442
extractComments : false ,
436
443
chunkFilter : ( chunk : compilation . Chunk ) =>
@@ -441,7 +448,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
441
448
// They are shared between ES2015 & ES5 outputs so must support ES5.
442
449
new TerserPlugin ( {
443
450
sourceMap : scriptsSourceMap ,
444
- parallel : true ,
451
+ parallel : maxCpus ,
445
452
cache : ! cachingDisabled && findCachePath ( 'terser-webpack' ) ,
446
453
extractComments : false ,
447
454
chunkFilter : ( chunk : compilation . Chunk ) =>
0 commit comments