forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-webpack.ts
More file actions
70 lines (59 loc) · 1.95 KB
/
Copy pathbuild-webpack.ts
File metadata and controls
70 lines (59 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as rimraf from 'rimraf';
import * as path from 'path';
const Task = require('../ember-cli/lib/models/task');
import * as webpack from 'webpack';
import { BuildOptions } from '../commands/build';
import { NgCliWebpackConfig } from '../models/webpack-config';
import { getWebpackStatsConfig } from '../models/';
import { CliConfig } from '../models/config';
// Configure build and output;
let lastHash: any = null;
export default <any>Task.extend({
run: function (runTaskOptions: BuildOptions) {
const project = this.cliProject;
const outputDir = runTaskOptions.outputPath || CliConfig.fromProject().config.apps[0].outDir;
rimraf.sync(path.resolve(project.root, outputDir));
const config = new NgCliWebpackConfig(
project,
runTaskOptions.target,
runTaskOptions.environment,
outputDir,
runTaskOptions.baseHref,
runTaskOptions.i18nFile,
runTaskOptions.i18nFormat,
runTaskOptions.locale,
runTaskOptions.aot,
runTaskOptions.sourcemap,
runTaskOptions.vendorChunk,
runTaskOptions.verbose,
runTaskOptions.progress
).config;
const webpackCompiler: any = webpack(config);
const statsConfig = getWebpackStatsConfig(runTaskOptions.verbose);
return new Promise((resolve, reject) => {
webpackCompiler.run((err: any, stats: any) => {
if (err) {
return reject(err);
}
// Don't keep cache
// TODO: Make conditional if using --watch
webpackCompiler.purgeInputFileSystem();
if (stats.hash !== lastHash) {
lastHash = stats.hash;
process.stdout.write(stats.toString(statsConfig) + '\n');
}
if (stats.hasErrors()) {
reject();
} else {
resolve();
}
});
})
.catch((err: Error) => {
if (err) {
this.ui.writeError('\nAn error occured during the build:\n' + ((err && err.stack) || err));
}
throw err;
});
}
});