Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(build): combine run and watch tasks #4093

Merged
merged 1 commit into from Jan 18, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 2 additions & 12 deletions packages/angular-cli/commands/build.run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Version } from '../upgrade/version';
import WebpackBuild from '../tasks/build-webpack';
import WebpackBuildWatch from '../tasks/build-webpack-watch';
import { BuildOptions } from './build';

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

const ui = this.ui;
const buildTask = commandOptions.watch ?
new WebpackBuildWatch({
const buildTask = new WebpackBuild({
cliProject: project,
ui: ui,
outputPath: commandOptions.outputPath,
target: commandOptions.target,
environment: commandOptions.environment
}) :
new WebpackBuild({
cliProject: project,
ui: ui,
ui: this.ui,
outputPath: commandOptions.outputPath,
target: commandOptions.target,
environment: commandOptions.environment,
Expand Down
60 changes: 0 additions & 60 deletions packages/angular-cli/tasks/build-webpack-watch.ts

This file was deleted.

27 changes: 13 additions & 14 deletions packages/angular-cli/tasks/build-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { getWebpackStatsConfig } from '../models/';
import { CliConfig } from '../models/config';


// Configure build and output;
let lastHash: any = null;

export default <any>Task.extend({
export default Task.extend({
run: function (runTaskOptions: BuildOptions) {

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

const webpackCompiler: any = webpack(config);

const webpackCompiler = webpack(config);
const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose);

return new Promise((resolve, reject) => {
webpackCompiler.run((err: any, stats: any) => {
const callback: webpack.compiler.CompilerCallback = (err, stats) => {
if (err) {
return reject(err);
}

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

if (stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(statsConfig) + '\n');
if (runTaskOptions.watch) {
return;
}

if (stats.hasErrors()) {
reject();
} else {
resolve();
}
});
};

if (runTaskOptions.watch) {
webpackCompiler.watch({}, callback);
} else {
webpackCompiler.run(callback);
}
})
.catch((err: Error) => {
if (err) {
Expand Down