Skip to content

Commit c97a0db

Browse files
committed
Added support for webpack stats JSON output
1 parent 3a85ffc commit c97a0db

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

packages/@angular/cli/commands/build.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,26 @@ export const baseBuildCommandOptions: any = [
3131
description: 'define the output filename cache-busting hashing mode',
3232
aliases: ['oh']
3333
},
34+
{ name: 'json', type: Boolean, default: false },
3435
];
3536

3637
export interface BuildTaskOptions extends BuildOptions {
3738
watch?: boolean;
39+
watcher?: string;
40+
supressSizes: boolean;
41+
baseHref?: string;
42+
aot?: boolean;
43+
sourcemap?: boolean;
44+
vendorChunk?: boolean;
45+
verbose?: boolean;
46+
progress?: boolean;
47+
i18nFile?: string;
48+
i18nFormat?: string;
49+
locale?: string;
50+
deployUrl?: string;
51+
outputHashing?: string;
52+
extractCss?: boolean | null;
53+
json?: boolean;
3854
}
3955

4056
const BuildCommand = Command.extend({

packages/@angular/cli/tasks/build.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BuildTaskOptions } from '../commands/build';
77
import { NgCliWebpackConfig } from '../models/webpack-config';
88
import { getWebpackStatsConfig } from '../models/webpack-configs/utils';
99
import { CliConfig } from '../models/config';
10+
const fs = require('fs');
1011

1112

1213
export default Task.extend({
@@ -36,6 +37,15 @@ export default Task.extend({
3637
return;
3738
}
3839

40+
if (!runTaskOptions.watch && runTaskOptions.json) {
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 {

tests/e2e/tests/build/json.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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', '--json')
8+
.then(() => expectFileToExist('./dist/stats.json'))
9+
.then(() => expectGitToBeClean());
10+
}

0 commit comments

Comments
 (0)