Skip to content

Commit a78fc95

Browse files
clydinMRHarrison
authored andcommitted
refactor(build): combine run and watch tasks (angular#4093)
1 parent 45841e8 commit a78fc95

File tree

3 files changed

+15
-86
lines changed

3 files changed

+15
-86
lines changed

packages/angular-cli/commands/build.run.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Version } from '../upgrade/version';
22
import WebpackBuild from '../tasks/build-webpack';
3-
import WebpackBuildWatch from '../tasks/build-webpack-watch';
43
import { BuildOptions } from './build';
54

65
export default function buildRun(commandOptions: BuildOptions) {
@@ -36,18 +35,9 @@ export default function buildRun(commandOptions: BuildOptions) {
3635
// Check angular version.
3736
Version.assertAngularVersionIs2_3_1OrHigher(project.root);
3837

39-
const ui = this.ui;
40-
const buildTask = commandOptions.watch ?
41-
new WebpackBuildWatch({
38+
const buildTask = new WebpackBuild({
4239
cliProject: project,
43-
ui: ui,
44-
outputPath: commandOptions.outputPath,
45-
target: commandOptions.target,
46-
environment: commandOptions.environment
47-
}) :
48-
new WebpackBuild({
49-
cliProject: project,
50-
ui: ui,
40+
ui: this.ui,
5141
outputPath: commandOptions.outputPath,
5242
target: commandOptions.target,
5343
environment: commandOptions.environment,

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

-60
This file was deleted.

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

+13-14
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import { getWebpackStatsConfig } from '../models/';
88
import { CliConfig } from '../models/config';
99

1010

11-
// Configure build and output;
12-
let lastHash: any = null;
13-
14-
export default <any>Task.extend({
11+
export default Task.extend({
1512
run: function (runTaskOptions: BuildOptions) {
1613

1714
const project = this.cliProject;
@@ -39,31 +36,33 @@ export default <any>Task.extend({
3936
runTaskOptions.extractCss,
4037
).config;
4138

42-
const webpackCompiler: any = webpack(config);
43-
39+
const webpackCompiler = webpack(config);
4440
const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose);
4541

4642
return new Promise((resolve, reject) => {
47-
webpackCompiler.run((err: any, stats: any) => {
43+
const callback: webpack.compiler.CompilerCallback = (err, stats) => {
4844
if (err) {
4945
return reject(err);
5046
}
5147

52-
// Don't keep cache
53-
// TODO: Make conditional if using --watch
54-
webpackCompiler.purgeInputFileSystem();
48+
this.ui.writeLine(stats.toString(statsConfig));
5549

56-
if (stats.hash !== lastHash) {
57-
lastHash = stats.hash;
58-
process.stdout.write(stats.toString(statsConfig) + '\n');
50+
if (runTaskOptions.watch) {
51+
return;
5952
}
6053

6154
if (stats.hasErrors()) {
6255
reject();
6356
} else {
6457
resolve();
6558
}
66-
});
59+
};
60+
61+
if (runTaskOptions.watch) {
62+
webpackCompiler.watch({}, callback);
63+
} else {
64+
webpackCompiler.run(callback);
65+
}
6766
})
6867
.catch((err: Error) => {
6968
if (err) {

0 commit comments

Comments
 (0)