File tree 4 files changed +24
-0
lines changed
4 files changed +24
-0
lines changed 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
94
94
` --extract-css ` (` -ec ` ) extract css from global styles onto css files instead of js ones
95
95
96
96
` --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 = [
31
31
description : 'define the output filename cache-busting hashing mode' ,
32
32
aliases : [ 'oh' ]
33
33
} ,
34
+ { name : 'statsJson' , type : Boolean , default : false } ,
34
35
] ;
35
36
36
37
export interface BuildTaskOptions extends BuildOptions {
37
38
watch ?: boolean ;
39
+ statsJson ?: boolean ;
38
40
}
39
41
40
42
const BuildCommand = Command . extend ( {
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { BuildTaskOptions } from '../commands/build';
7
7
import { NgCliWebpackConfig } from '../models/webpack-config' ;
8
8
import { getWebpackStatsConfig } from '../models/webpack-configs/utils' ;
9
9
import { CliConfig } from '../models/config' ;
10
+ const fs = require ( 'fs' ) ;
10
11
11
12
12
13
export default Task . extend ( {
@@ -36,6 +37,15 @@ export default Task.extend({
36
37
return ;
37
38
}
38
39
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
+
39
49
if ( stats . hasErrors ( ) ) {
40
50
reject ( ) ;
41
51
} 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