Skip to content

Commit a5c18ad

Browse files
committed
Added support for webpack stats JSON output
1 parent 75e83a4 commit a5c18ad

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

packages/angular-cli/commands/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface BuildOptions {
1919
deployUrl?: string;
2020
outputHashing?: string;
2121
extractCss?: boolean | null;
22+
json?: boolean;
2223
}
2324

2425
const BuildCommand = Command.extend({
@@ -54,7 +55,8 @@ const BuildCommand = Command.extend({
5455
values: ['none', 'all', 'media', 'bundles'],
5556
description: 'define the output filename cache-busting hashing mode'
5657
},
57-
{ name: 'extract-css', type: Boolean, default: true }
58+
{ name: 'extract-css', type: Boolean, default: true },
59+
{ name: 'json', type: Boolean, default: false },
5860
],
5961

6062
run: function (commandOptions: BuildOptions) {

packages/angular-cli/tasks/build-webpack.ts

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

1011

1112
export default Task.extend({
@@ -51,6 +52,15 @@ export default Task.extend({
5152
return;
5253
}
5354

55+
if (!runTaskOptions.watch && runTaskOptions.json) {
56+
const jsonStats = stats.toJson('verbose');
57+
58+
fs.writeFileSync(
59+
path.resolve(project.root, outputDir, 'stats.json'),
60+
JSON.stringify(jsonStats, null, 2)
61+
);
62+
}
63+
5464
if (stats.hasErrors()) {
5565
reject();
5666
} 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)