angular-cli/packages/schematics/angular/migrations/update-16/update-server-builder-config.ts
Alan Agius 873272f644 fix(@schematics/angular): provide migration that disables build optimizer on dev server builds
In https://github.com/angular/angular-cli/pull/25070 we turned on `buildOptimizer` by default for server builds. This causes existing projects development builds to always run build-optimizer. This migration will set `buildOptimizer` to false, when `optimization` is disabled.
2023-04-27 12:25:54 +00:00

31 lines
990 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { Rule } from '@angular-devkit/schematics';
import { allTargetOptions, updateWorkspace } from '../../utility/workspace';
import { Builders } from '../../utility/workspace-models';
export default function (): Rule {
return updateWorkspace((workspace) => {
for (const project of workspace.projects.values()) {
for (const target of project.targets.values()) {
if (target.builder !== Builders.Server) {
continue;
}
for (const [, options] of allTargetOptions(target)) {
// Set 'buildOptimizer' to match the 'optimization' option.
if (options.buildOptimizer === undefined && options.optimization !== undefined) {
options.buildOptimizer = !!options.optimization;
}
}
}
}
});
}