Skip to content

Commit

Permalink
fix(@angular/build): disable TypeScript removeComments option
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
alan-agius4 committed Jan 24, 2025
1 parent 94643d5 commit bd9d379
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bd9d379

Please sign in to comment.