Skip to content

Commit 6e051c9

Browse files
committed
fix(@angular-devkit/build-angular): set public class fields as properties
Configure Babel to use `setPublicClassFields: true`. As when shipping Angular packages without `"useDefineForClassFields": false` will increase the bundle size of an ng-new app by ~2Kb when `useDefineForClassFields is not false. due to the additional `_defineProperty`, which will be added on every class property. See: https://babeljs.io/docs/babel-plugin-proposal-class-properties
1 parent afc8704 commit 6e051c9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/angular_devkit/build_angular/src/babel/presets/application.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ export default function (api: unknown, options: ApplicationPresetOptions) {
211211
targets: options.supportedBrowsers,
212212
include: includePlugins,
213213
exclude: ['transform-typeof-symbol'],
214+
assumptions: {
215+
// Use `setPublicClassFields: true` to avoid decrease bundle sizes
216+
// when targetting ES2022+ with `useDefineForClassFields: true`.
217+
// This is because ervery property of the class will otherwise be wrapped in a `_defineProperty`.
218+
// This is not needed for TypeScript as TS itself will emit the right decleration of class properties.
219+
setPublicClassFields: true,
220+
},
214221
},
215222
]);
216223
needRuntimeTransform = true;

0 commit comments

Comments
 (0)