File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,3 +94,5 @@ or `ng serve --prod` will also make use of uglifying and tree-shaking functional
9494` --extract-css ` (` -ec ` ) extract css from global styles onto css files instead of js ones
9595
9696` --output-hashing ` define the output filename cache-busting hashing mode
97+
98+ ` --stats-json ` generates a ` stats.json ` file which can be analyzed using tools such as: ` webpack-bundle-analyzer ` or https://webpack.github.io/analyse
Original file line number Diff line number Diff line change @@ -31,10 +31,12 @@ export const baseBuildCommandOptions: any = [
3131 description : 'define the output filename cache-busting hashing mode' ,
3232 aliases : [ 'oh' ]
3333 } ,
34+ { name : 'stats-json' , type : Boolean , default : false } ,
3435] ;
3536
3637export interface BuildTaskOptions extends BuildOptions {
3738 watch ?: boolean ;
39+ statsJson ?: boolean ;
3840}
3941
4042const BuildCommand = Command . extend ( {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { BuildTaskOptions } from '../commands/build';
77import { NgCliWebpackConfig } from '../models/webpack-config' ;
88import { getWebpackStatsConfig } from '../models/webpack-configs/utils' ;
99import { CliConfig } from '../models/config' ;
10+ const fs = require ( 'fs' ) ;
1011
1112
1213export default Task . extend ( {
@@ -36,6 +37,15 @@ export default Task.extend({
3637 return ;
3738 }
3839
40+ if ( ! runTaskOptions . watch && runTaskOptions . statsJson ) {
41+ const jsonStats = stats . toJson ( 'verbose' ) ;
42+
43+ fs . writeFileSync (
44+ path . resolve ( project . root , outputPath , 'stats.json' ) ,
45+ JSON . stringify ( jsonStats , null , 2 )
46+ ) ;
47+ }
48+
3949 if ( stats . hasErrors ( ) ) {
4050 reject ( ) ;
4151 } else {
Original file line number Diff line number Diff line change 1+ import { ng } from '../../utils/process' ;
2+ import { expectFileToExist } from '../../utils/fs' ;
3+ import { expectGitToBeClean } from '../../utils/git' ;
4+
5+
6+ export default function ( ) {
7+ return ng ( 'build' , '--stats-json' )
8+ . then ( ( ) => expectFileToExist ( './dist/stats.json' ) )
9+ . then ( ( ) => expectGitToBeClean ( ) ) ;
10+ }
You can’t perform that action at this time.
0 commit comments