Skip to content

Commit 1519b63

Browse files
committed
feat(build): add --verbose and --progress flags
Currently builds output a lot of information, some of which can hide errors, by default. This PR cuts down on the information shown and adds a `--verbose` flag to restore previous build output. A `--progress` flag is also present to turn off progress logging in CI environments. Fix #1836 Fix #2012
1 parent fe4b35b commit 1519b63

File tree

12 files changed

+101
-52
lines changed

12 files changed

+101
-52
lines changed

packages/angular-cli/commands/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface BuildOptions {
1212
baseHref?: string;
1313
aot?: boolean;
1414
sourcemap?: boolean;
15+
verbose?: boolean;
16+
progress?: boolean;
1517
}
1618

1719
const BuildCommand = Command.extend({
@@ -33,7 +35,9 @@ const BuildCommand = Command.extend({
3335
{ name: 'suppress-sizes', type: Boolean, default: false },
3436
{ name: 'base-href', type: String, default: null, aliases: ['bh'] },
3537
{ name: 'aot', type: Boolean, default: false },
36-
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] }
38+
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
39+
{ name: 'verbose', type: Boolean, default: false },
40+
{ name: 'progress', type: Boolean, default: true }
3741
],
3842

3943
run: function (commandOptions: BuildOptions) {

packages/angular-cli/commands/serve.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export interface ServeTaskOptions {
2727
sslCert?: string;
2828
aot?: boolean;
2929
sourcemap?: boolean;
30+
verbose?: boolean;
31+
progress?: boolean;
3032
open?: boolean;
3133
}
3234

@@ -83,6 +85,8 @@ const ServeCommand = Command.extend({
8385
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
8486
{ name: 'aot', type: Boolean, default: false },
8587
{ name: 'sourcemap', type: Boolean, default: true, aliases: ['sm'] },
88+
{ name: 'verbose', type: Boolean, default: false },
89+
{ name: 'progress', type: Boolean, default: true },
8690
{
8791
name: 'open',
8892
type: Boolean,

packages/angular-cli/commands/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface TestOptions {
1414
reporters?: string;
1515
build?: boolean;
1616
sourcemap?: boolean;
17+
progress?: boolean;
1718
}
1819

1920

@@ -23,6 +24,7 @@ const NgCliTestCommand = TestCommand.extend({
2324
{ name: 'code-coverage', type: Boolean, default: false, aliases: ['cc'] },
2425
{ name: 'lint', type: Boolean, default: false, aliases: ['l'] },
2526
{ name: 'single-run', type: Boolean, default: false, aliases: ['sr'] },
27+
{ name: 'progress', type: Boolean, default: true},
2628
{ name: 'browsers', type: String },
2729
{ name: 'colors', type: Boolean },
2830
{ name: 'log-level', type: String },

packages/angular-cli/models/webpack-build-production.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ declare module 'webpack' {
1414
}
1515
}
1616

17-
export const getWebpackProdConfigPartial = function(projectRoot: string, appConfig: any) {
17+
export const getWebpackProdConfigPartial = function(projectRoot: string,
18+
appConfig: any,
19+
verbose: any) {
1820
const appRoot = path.resolve(projectRoot, appConfig.root);
1921
const styles = appConfig.styles
2022
? appConfig.styles.map((style: string) => path.resolve(appRoot, style))
2123
: [];
2224
const cssLoaders = ['css-loader?sourcemap&minimize', 'postcss-loader'];
25+
2326
return {
2427
output: {
2528
path: path.resolve(projectRoot, appConfig.outDir),
@@ -57,7 +60,7 @@ export const getWebpackProdConfigPartial = function(projectRoot: string, appConf
5760
}),
5861
new webpack.optimize.UglifyJsPlugin(<any>{
5962
mangle: { screw_ie8 : true },
60-
compress: { screw_ie8: true },
63+
compress: { screw_ie8: true, warnings: verbose },
6164
sourceMap: true
6265
}),
6366
new CompressionPlugin({

packages/angular-cli/models/webpack-build-test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const webpackLoader = g['angularCliIsLocal']
1010
? g.angularCliPackages['@ngtools/webpack'].main
1111
: '@ngtools/webpack';
1212

13+
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
1314

1415
const getWebpackTestConfig = function (projectRoot, environment, appConfig, testConfig) {
1516

1617
const appRoot = path.resolve(projectRoot, appConfig.root);
17-
const extraRules = [];
18-
const extraPlugins = [];
18+
var extraRules = [];
19+
var extraPlugins = [];
1920

2021
if (testConfig.codeCoverage) {
2122
extraRules.push({
@@ -49,6 +50,10 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig, test
4950
}))
5051
}
5152

53+
if (testConfig.progress) {
54+
extraPlugins.push(new ProgressPlugin({ colors: true }));
55+
}
56+
5257
return {
5358
devtool: testConfig.sourcemap ? 'inline-source-map' : 'eval',
5459
context: path.resolve(__dirname, './'),

packages/angular-cli/models/webpack-build-utils.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ export const ngAppResolve = (resolvePath: string): string => {
66

77
export const webpackOutputOptions = {
88
colors: true,
9+
hash: true,
10+
timings: true,
911
chunks: true,
12+
chunkModules: false,
13+
children: false, // listing all children is very noisy in AOT and hides warnings/errors
1014
modules: false,
1115
reasons: false,
12-
chunkModules: false
16+
warnings: true,
17+
assets: false, // listing all assets is very noisy when using assets directories
18+
version: false
1319
};
1420

15-
export const webpackDevServerOutputOptions = {
21+
export const verboseWebpackOutputOptions = {
22+
children: true,
1623
assets: true,
17-
colors: true,
1824
version: true,
19-
hash: true,
20-
timings: true,
21-
chunks: false,
22-
chunkModules: false
25+
reasons: true,
26+
chunkModules: false // TODO: set to true when console to file output is fixed
2327
};

packages/angular-cli/models/webpack-config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class NgCliWebpackConfig {
2525
baseHref?: string,
2626
isAoT = false,
2727
sourcemap = true,
28+
verbose = false
2829
) {
2930
const config: CliConfig = CliConfig.fromProject();
3031
const appConfig = config.config.apps[0];
@@ -38,7 +39,7 @@ export class NgCliWebpackConfig {
3839
baseHref,
3940
sourcemap
4041
);
41-
let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig);
42+
let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig, verbose);
4243
const typescriptConfigPartial = isAoT
4344
? getWebpackAotConfigPartial(this.ngCliProject.root, appConfig)
4445
: getWebpackNonAotConfigPartial(this.ngCliProject.root, appConfig);
@@ -60,12 +61,12 @@ export class NgCliWebpackConfig {
6061
);
6162
}
6263

63-
getTargetConfig(projectRoot: string, appConfig: any): any {
64+
getTargetConfig(projectRoot: string, appConfig: any, verbose: boolean): any {
6465
switch (this.target) {
6566
case 'development':
6667
return getWebpackDevConfigPartial(projectRoot, appConfig);
6768
case 'production':
68-
return getWebpackProdConfigPartial(projectRoot, appConfig);
69+
return getWebpackProdConfigPartial(projectRoot, appConfig, verbose);
6970
default:
7071
throw new Error("Invalid build target. Only 'development' and 'production' are available.");
7172
}

packages/angular-cli/plugins/karma.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const init = (config) => {
1313
const testConfig = {
1414
codeCoverage: config.angularCli.codeCoverage || false,
1515
lint: config.angularCli.lint || false,
16-
sourcemap: config.angularCli.sourcemap
16+
sourcemap: config.angularCli.sourcemap,
17+
progress: config.angularCli.progress
1718
}
1819

1920
// add webpack config

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Task = require('../ember-cli/lib/models/task');
44
import * as webpack from 'webpack';
55
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
66
import { NgCliWebpackConfig } from '../models/webpack-config';
7-
import { webpackOutputOptions } from '../models/';
7+
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
88
import { BuildOptions } from '../commands/build';
99
import { CliConfig } from '../models/config';
1010

@@ -25,13 +25,21 @@ export default Task.extend({
2525
outputDir,
2626
runTaskOptions.baseHref,
2727
runTaskOptions.aot,
28-
runTaskOptions.sourcemap
28+
runTaskOptions.sourcemap,
29+
runTaskOptions.verbose,
2930
).config;
3031
const webpackCompiler: any = webpack(config);
3132

32-
webpackCompiler.apply(new ProgressPlugin({
33-
profile: true
34-
}));
33+
const statsOptions = runTaskOptions.verbose
34+
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
35+
: webpackOutputOptions;
36+
37+
if (runTaskOptions.progress) {
38+
webpackCompiler.apply(new ProgressPlugin({
39+
profile: runTaskOptions.verbose,
40+
colors: true
41+
}));
42+
}
3543

3644
return new Promise((resolve, reject) => {
3745
webpackCompiler.watch({}, (err: any, stats: any) => {
@@ -44,7 +52,7 @@ export default Task.extend({
4452

4553
if (stats.hash !== lastHash) {
4654
lastHash = stats.hash;
47-
process.stdout.write(stats.toString(webpackOutputOptions) + '\n');
55+
process.stdout.write(stats.toString(statsOptions) + '\n');
4856
}
4957
});
5058
});

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as rimraf from 'rimraf';
22
import * as path from 'path';
33
const Task = require('../ember-cli/lib/models/task');
44
import * as webpack from 'webpack';
5+
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
56
import { BuildOptions } from '../commands/build';
67
import { NgCliWebpackConfig } from '../models/webpack-config';
7-
import { webpackOutputOptions } from '../models/';
8+
import { webpackOutputOptions, verboseWebpackOutputOptions } from '../models/';
89
import { CliConfig } from '../models/config';
910

1011
// Configure build and output;
@@ -24,16 +25,22 @@ export default <any>Task.extend({
2425
outputDir,
2526
runTaskOptions.baseHref,
2627
runTaskOptions.aot,
27-
runTaskOptions.sourcemap
28+
runTaskOptions.sourcemap,
29+
runTaskOptions.verbose
2830
).config;
2931

3032
const webpackCompiler: any = webpack(config);
3133

32-
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
34+
const statsOptions = runTaskOptions.verbose
35+
? Object.assign(webpackOutputOptions, verboseWebpackOutputOptions)
36+
: webpackOutputOptions;
3337

34-
webpackCompiler.apply(new ProgressPlugin({
35-
profile: true
36-
}));
38+
if (runTaskOptions.progress) {
39+
webpackCompiler.apply(new ProgressPlugin({
40+
profile: runTaskOptions.verbose,
41+
colors: true
42+
}));
43+
}
3744

3845
return new Promise((resolve, reject) => {
3946
webpackCompiler.run((err: any, stats: any) => {
@@ -45,7 +52,7 @@ export default <any>Task.extend({
4552

4653
if (stats.hash !== lastHash) {
4754
lastHash = stats.hash;
48-
process.stdout.write(stats.toString(webpackOutputOptions) + '\n');
55+
process.stdout.write(stats.toString(statsOptions) + '\n');
4956
}
5057

5158
return stats.hasErrors() ? reject() : resolve();

0 commit comments

Comments
 (0)