diff --git a/packages/angular/build/src/utils/environment-options.ts b/packages/angular/build/src/utils/environment-options.ts index 24d59b9fd384..c1e330b37963 100644 --- a/packages/angular/build/src/utils/environment-options.ts +++ b/packages/angular/build/src/utils/environment-options.ts @@ -6,6 +6,8 @@ * found in the LICENSE file at https://angular.dev/license */ +import { availableParallelism } from 'node:os'; + function isDisabled(variable: string): boolean { return variable === '0' || variable.toLowerCase() === 'false'; } @@ -74,7 +76,9 @@ export const allowMinify = debugOptimize.minify; * */ const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS']; -export const maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable : 4; +export const maxWorkers = isPresent(maxWorkersVariable) + ? +maxWorkersVariable + : Math.min(4, availableParallelism()); const parallelTsVariable = process.env['NG_BUILD_PARALLEL_TS']; export const useParallelTs = !isPresent(parallelTsVariable) || !isDisabled(parallelTsVariable); diff --git a/packages/angular_devkit/build_angular/src/utils/environment-options.ts b/packages/angular_devkit/build_angular/src/utils/environment-options.ts index 24d59b9fd384..c1e330b37963 100644 --- a/packages/angular_devkit/build_angular/src/utils/environment-options.ts +++ b/packages/angular_devkit/build_angular/src/utils/environment-options.ts @@ -6,6 +6,8 @@ * found in the LICENSE file at https://angular.dev/license */ +import { availableParallelism } from 'node:os'; + function isDisabled(variable: string): boolean { return variable === '0' || variable.toLowerCase() === 'false'; } @@ -74,7 +76,9 @@ export const allowMinify = debugOptimize.minify; * */ const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS']; -export const maxWorkers = isPresent(maxWorkersVariable) ? +maxWorkersVariable : 4; +export const maxWorkers = isPresent(maxWorkersVariable) + ? +maxWorkersVariable + : Math.min(4, availableParallelism()); const parallelTsVariable = process.env['NG_BUILD_PARALLEL_TS']; export const useParallelTs = !isPresent(parallelTsVariable) || !isDisabled(parallelTsVariable);