Skip to content

Commit bee2dde

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 bee2dde

File tree

1 file changed

+7
-0
lines changed
  • packages/angular_devkit/build_angular/src/webpack/configs

1 file changed

+7
-0
lines changed

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

+7
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,13 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
411411
{
412412
loader: require.resolve('../../babel/webpack-loader'),
413413
options: {
414+
assumptions: {
415+
// Use `setPublicClassFields: true` to avoid decrease bundle sizes
416+
// when targetting ES2022+ with `useDefineForClassFields: true`.
417+
// This is because ervery property of the class will otherwise be wrapped in a `_defineProperty`.
418+
// This is not needed for TypeScript as TS itself will emit the right decleration of class properties.
419+
setPublicClassFields: true,
420+
},
414421
cacheDirectory: (cache.enabled && path.join(cache.path, 'babel-webpack')) || false,
415422
aot: buildOptions.aot,
416423
optimize: buildOptions.buildOptimizer,

0 commit comments

Comments
 (0)