Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/documentation/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ or `ng serve --prod` will also make use of uglifying and tree-shaking functional
`--extract-css` (`-ec`) extract css from global styles onto css files instead of js ones

`--output-hashing` define the output filename cache-busting hashing mode

`--stats-json` generates a `stats.json` file which can be analyzed using tools such as: `webpack-bundle-analyzer` or https://webpack.github.io/analyse
2 changes: 2 additions & 0 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export const baseBuildCommandOptions: any = [
description: 'define the output filename cache-busting hashing mode',
aliases: ['oh']
},
{ name: 'stats-json', type: Boolean, default: false },
];

export interface BuildTaskOptions extends BuildOptions {
watch?: boolean;
statsJson?: boolean;
}

const BuildCommand = Command.extend({
Expand Down
10 changes: 10 additions & 0 deletions packages/@angular/cli/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BuildTaskOptions } from '../commands/build';
import { NgCliWebpackConfig } from '../models/webpack-config';
import { getWebpackStatsConfig } from '../models/webpack-configs/utils';
import { CliConfig } from '../models/config';
const fs = require('fs');


export default Task.extend({
Expand Down Expand Up @@ -36,6 +37,15 @@ export default Task.extend({
return;
}

if (!runTaskOptions.watch && runTaskOptions.statsJson) {
const jsonStats = stats.toJson('verbose');

fs.writeFileSync(
path.resolve(project.root, outputPath, 'stats.json'),
JSON.stringify(jsonStats, null, 2)
);
}

if (stats.hasErrors()) {
reject();
} else {
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/tests/build/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ng} from '../../utils/process';
import {expectFileToExist} from '../../utils/fs';
import {expectGitToBeClean} from '../../utils/git';


export default function() {
return ng('build', '--stats-json')
.then(() => expectFileToExist('./dist/stats.json'))
.then(() => expectGitToBeClean());
}