Skip to content

Commit 7a55eb7

Browse files
committed
Added support for webpack stats JSON output
1 parent cbab6f8 commit 7a55eb7

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
@@ -30,10 +30,26 @@ export const BaseBuildCommandOptions: any = [
3030
description: 'define the output filename cache-busting hashing mode',
3131
aliases: ['oh']
3232
},
33+
{ name: 'json', type: Boolean, default: false },
3334
];
3435

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

3955
const BuildCommand = Command.extend({

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

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

1011

1112
export default Task.extend({
@@ -32,6 +33,15 @@ export default Task.extend({
3233
return;
3334
}
3435

36+
if (!runTaskOptions.watch && runTaskOptions.json) {
37+
const jsonStats = stats.toJson('verbose');
38+
39+
fs.writeFileSync(
40+
path.resolve(project.root, outputPath, 'stats.json'),
41+
JSON.stringify(jsonStats, null, 2)
42+
);
43+
}
44+
3545
if (stats.hasErrors()) {
3646
reject();
3747
} 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)