Skip to content

Commit bd9d379

Browse files
committed
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 (cherry picked from commit 1a3ef3b)
1 parent 94643d5 commit bd9d379

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/angular/build/src/tools/angular/compilation/angular-compilation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export abstract class AngularCompilation {
6363
enableResourceInlining: false,
6464
supportTestBed: false,
6565
supportJitMode: false,
66+
// Disable removing of comments as TS is quite aggressive with these and can
67+
// remove important annotations, such as /* @__PURE__ */ and comments like /* vite-ignore */.
68+
removeComments: false,
6669
}),
6770
);
6871
}

packages/angular_devkit/build_angular/src/tools/webpack/plugins/typescript.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ export function createIvyPlugin(
2323
sourceMap: buildOptions.sourceMap.scripts,
2424
declaration: false,
2525
declarationMap: false,
26+
// Disable removing of comments as TS is quite aggressive with these and can
27+
// remove important annotations, such as /* @__PURE__ */.
28+
removeComments: false,
2629
};
2730

2831
if (tsConfig.options.target === undefined || tsConfig.options.target < ScriptTarget.ES2022) {

0 commit comments

Comments
 (0)