Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): limit CPUs used by terser-webpack…
Browse files Browse the repository at this point in the history
…-plugin

Should help with #16860 (comment)
  • Loading branch information
filipesilva authored and Keen Yee Liau committed Feb 18, 2020
1 parent 9188467 commit fd13313
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) =>
Expand All @@ -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) =>
Expand Down

0 comments on commit fd13313

Please sign in to comment.