-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.js
53 lines (41 loc) · 1.18 KB
/
build.js
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
/**
* Wrapper for running webpack
*/
const webpack = require('webpack');
const path = require('path');
const fs = require('fs-extra');
const log = require('debug')('build:process');
const logError = require('debug')('build:error');
const logSuccessError = require('debug')('build:success:error');
const logSuccessWarning = require('debug')('build:success:warning');
logError.color = 1;
logSuccessError.color = 5;
logSuccessWarning.color = 3;
function build() {
const config = require('./webpack.config.js');
// Make sure build path is exist, if not create it
log(`> Cleaning output folder ${config.output.path} ...`);
fs.emptyDirSync(config.output.path);
return new Promise((resolve, reject) => {
webpack(config).run((err, stats) => {
if (err) {
logError(err.stack || err);
if (err.details) {
logError(err.details);
}
reject(err);
} else {
const info = stats.toJson();
if (stats.hasErrors()) {
logSuccessError(info.errors);
process.exit(1);
}
if (stats.hasWarnings()) {
logSuccessWarning(info.warnings);
}
resolve();
}
});
});
}
build();