Skip to content

Commit 197d73d

Browse files
alan-agius4filipesilva
authored andcommitted
fix(@angular-devkit/build-angular): show bundle sizes with 2 decimal places
Before ``` Initial Chunk Files | Names | Size vendor.js | vendor | 2.07 MB polyfills.js | polyfills | 141.3 kb main.js | main | 55.77 kb runtime.js | runtime | 6.15 kb styles.css | styles | 119 bytes ``` After ``` Initial Chunk Files | Names | Size vendor.js | vendor | 2.07 MB polyfills.js | polyfills | 141.30 kb main.js | main | 55.77 kb runtime.js | runtime | 6.15 kb styles.css | styles | 119 bytes ```
1 parent 38ed278 commit 197d73d

File tree

1 file changed

+4
-2
lines changed
  • packages/angular_devkit/build_angular/src/webpack/utils

1 file changed

+4
-2
lines changed

packages/angular_devkit/build_angular/src/webpack/utils/stats.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ export function formatSize(size: number): string {
2121

2222
const abbreviations = ['bytes', 'kB', 'MB', 'GB'];
2323
const index = Math.floor(Math.log(size) / Math.log(1024));
24-
25-
return `${+(size / Math.pow(1024, index)).toPrecision(3)} ${abbreviations[index]}`;
24+
const roundedSize = size / Math.pow(1024, index);
25+
// bytes don't have a fraction
26+
const fractionDigits = index === 0 ? 0 : 2;
27+
return `${roundedSize.toFixed(fractionDigits)} ${abbreviations[index]}`;
2628
}
2729

2830
export type BundleStatsData = [files: string, names: string, size: number | string];

0 commit comments

Comments
 (0)