From 1a3ef3b60bb1d383a514dee8a6f95b7e15b5bb2c Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 24 Jan 2025 10:39:21 +0000 Subject: [PATCH] fix(@angular/build): disable TypeScript `removeComments` option Disables TypeScript's `removeComments` option to ensure important annotations like `/* @__PURE__ */` and `/* vite-ignore */` are preserved. TypeScript's comment removal can be too aggressive, potentially stripping out critical information needed by bundlers for dead code elimination. Non-essential comments will be handled by the bundler, so removing them in TypeScript isn't necessary and could lead to an increase in the final bundle size. Closes #29470 --- .../build/src/tools/angular/compilation/angular-compilation.ts | 3 +++ .../build_angular/src/tools/webpack/plugins/typescript.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/angular/build/src/tools/angular/compilation/angular-compilation.ts b/packages/angular/build/src/tools/angular/compilation/angular-compilation.ts index 2e44e0bdab33..bea3c65e1b8a 100644 --- a/packages/angular/build/src/tools/angular/compilation/angular-compilation.ts +++ b/packages/angular/build/src/tools/angular/compilation/angular-compilation.ts @@ -63,6 +63,9 @@ export abstract class AngularCompilation { enableResourceInlining: false, supportTestBed: false, supportJitMode: false, + // Disable removing of comments as TS is quite aggressive with these and can + // remove important annotations, such as /* @__PURE__ */ and comments like /* vite-ignore */. + removeComments: false, }), ); } diff --git a/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts index 537d809562c9..129c869036d2 100644 --- a/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts +++ b/packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts @@ -23,6 +23,9 @@ export function createIvyPlugin( sourceMap: buildOptions.sourceMap.scripts, declaration: false, declarationMap: false, + // Disable removing of comments as TS is quite aggressive with these and can + // remove important annotations, such as /* @__PURE__ */. + removeComments: false, }; if (tsConfig.options.target === undefined || tsConfig.options.target < ScriptTarget.ES2022) {