Skip to content

Commit

Permalink
refactor progress plugin to common config
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Nov 26, 2016
1 parent 14ead71 commit 715ad55
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 26 deletions.
12 changes: 11 additions & 1 deletion packages/angular-cli/models/webpack-build-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {GlobCopyWebpackPlugin} from '../plugins/glob-copy-webpack-plugin';
import {packageChunkSort} from '../utilities/package-chunk-sort';
import {BaseHrefWebpackPlugin} from '@angular-cli/base-href-webpack';

const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');

Expand All @@ -14,7 +15,9 @@ export function getWebpackCommonConfig(
appConfig: any,
baseHref: string,
sourcemap: boolean,
vendorChunk: boolean
vendorChunk: boolean,
verbose: boolean,
progress: boolean
) {

const appRoot = path.resolve(projectRoot, appConfig.root);
Expand Down Expand Up @@ -44,6 +47,13 @@ export function getWebpackCommonConfig(
}));
}

if (progress) {
extraPlugins.push(new ProgressPlugin({
profile: verbose,
colors: true
}));
}

return {
devtool: sourcemap ? 'source-map' : false,
resolve: {
Expand Down
7 changes: 5 additions & 2 deletions packages/angular-cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export class NgCliWebpackConfig {
isAoT = false,
sourcemap = true,
vendorChunk = false,
verbose = false
verbose = false,
progress = true
) {
const config: CliConfig = CliConfig.fromProject();
const appConfig = config.config.apps[0];
Expand All @@ -39,7 +40,9 @@ export class NgCliWebpackConfig {
appConfig,
baseHref,
sourcemap,
vendorChunk
vendorChunk,
verbose,
progress
);
let targetConfigPartial = this.getTargetConfig(this.ngCliProject.root, appConfig, verbose);
const typescriptConfigPartial = isAoT
Expand Down
8 changes: 1 addition & 7 deletions packages/angular-cli/tasks/build-webpack-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ export default Task.extend({
runTaskOptions.sourcemap,
runTaskOptions.vendorChunk,
runTaskOptions.verbose,
runTaskOptions.progress
).config;
const webpackCompiler: any = webpack(config);

const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose);

if (runTaskOptions.progress) {
webpackCompiler.apply(new ProgressPlugin({
profile: runTaskOptions.verbose,
colors: true
}));
}

return new Promise((resolve, reject) => {
webpackCompiler.watch({}, (err: any, stats: any) => {
if (err) {
Expand Down
10 changes: 2 additions & 8 deletions packages/angular-cli/tasks/build-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,14 @@ export default <any>Task.extend({
runTaskOptions.aot,
runTaskOptions.sourcemap,
runTaskOptions.vendorChunk,
runTaskOptions.verbose
runTaskOptions.verbose,
runTaskOptions.progress
).config;

const webpackCompiler: any = webpack(config);

const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose);

if (runTaskOptions.progress) {
webpackCompiler.apply(new ProgressPlugin({
profile: runTaskOptions.verbose,
colors: true
}));
}

return new Promise((resolve, reject) => {
webpackCompiler.run((err: any, stats: any) => {
if (err) { return reject(err); }
Expand Down
10 changes: 2 additions & 8 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default Task.extend({
serveTaskOptions.aot,
serveTaskOptions.sourcemap,
serveTaskOptions.vendorChunk,
serveTaskOptions.verbose
serveTaskOptions.verbose,
serveTaskOptions.progress
).config;

// This allows for live reload of page when changes are made to repo.
Expand All @@ -41,13 +42,6 @@ export default Task.extend({

const statsConfig = getWebpackStatsConfig(serveTaskOptions.verbose);

if (serveTaskOptions.progress) {
webpackCompiler.apply(new ProgressPlugin({
profile: serveTaskOptions.verbose,
colors: true
}));
}

let proxyConfig = {};
if (serveTaskOptions.proxyConfig) {
const proxyPath = path.resolve(this.project.root, serveTaskOptions.proxyConfig);
Expand Down

0 comments on commit 715ad55

Please sign in to comment.