UNPKG

2.12 kBJavaScriptView Raw
1"use strict";
2const rimraf = require('rimraf');
3const path = require('path');
4const Task = require('../ember-cli/lib/models/task');
5const SilentError = require('silent-error');
6const webpack = require('webpack');
7const webpack_config_1 = require('../models/webpack-config');
8const utils_1 = require('../models/webpack-configs/utils');
9const config_1 = require('../models/config');
10Object.defineProperty(exports, "__esModule", { value: true });
11exports.default = Task.extend({
12 run: function (runTaskOptions) {
13 const project = this.cliProject;
14 const outputPath = runTaskOptions.outputPath || config_1.CliConfig.fromProject().config.apps[0].outDir;
15 if (project.root === outputPath) {
16 throw new SilentError('Output path MUST not be project root directory!');
17 }
18 rimraf.sync(path.resolve(project.root, outputPath));
19 const webpackConfig = new webpack_config_1.NgCliWebpackConfig(runTaskOptions).config;
20 const webpackCompiler = webpack(webpackConfig);
21 const statsConfig = utils_1.getWebpackStatsConfig(runTaskOptions.verbose);
22 return new Promise((resolve, reject) => {
23 const callback = (err, stats) => {
24 if (err) {
25 return reject(err);
26 }
27 this.ui.writeLine(stats.toString(statsConfig));
28 if (runTaskOptions.watch) {
29 return;
30 }
31 if (stats.hasErrors()) {
32 reject();
33 }
34 else {
35 resolve();
36 }
37 };
38 if (runTaskOptions.watch) {
39 webpackCompiler.watch({}, callback);
40 }
41 else {
42 webpackCompiler.run(callback);
43 }
44 })
45 .catch((err) => {
46 if (err) {
47 this.ui.writeError('\nAn error occured during the build:\n' + ((err && err.stack) || err));
48 }
49 throw err;
50 });
51 }
52});
53//# sourceMappingURL=/Users/hansl/Sources/angular-cli/packages/@angular/cli/tasks/build.js.map
\No newline at end of file