-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (37 loc) · 1.11 KB
/
index.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
const _ = require('lodash');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const chalk = require('chalk');
const log = console.log;
module.exports = function (appRoot, config) {
const configObj = _.merge(webpackConfig(appRoot), config);
if (config.mode === 'development') {
log(chalk.black.bgGreen('Running in DEVELOPMENT mode'));
return webpack(configObj).watch({}, (err, stats) => {
errorHandler(err, stats, 'Watching files...');
});
}
if (config.mode === 'production') {
log(chalk.black.bgGreen('Running in PRODUCTION mode'));
return webpack(configObj).run((err, stats) => {
errorHandler(err, stats, 'Assets compiled');
});
}
function errorHandler (err, stats, complete) {
if (err) {
console.error(err.stack || err);
if (err.details) {
log(chalk.red(err.details));
}
return;
}
const info = stats.toJson();
if (stats.hasErrors()) {
log(chalk.red(info.errors));
}
if (stats.hasWarnings()) {
log(chalk.yellow(info.warnings));
}
log(chalk.green(`${complete}`));
}
};