1 | const webpack = require('webpack');
|
2 | const chalk = require('chalk');
|
3 | const webpackConfig = require('../configuration/webpack/webpackConfig');
|
4 | module.exports = function (program) {
|
5 | const cfg = webpackConfig(program, 'build');
|
6 | const compiler = webpack(cfg.webpack);
|
7 | function callback(err, stats){
|
8 | const options = {
|
9 | assets: true,
|
10 | modules: false,
|
11 | children: false,
|
12 | cached: false,
|
13 | errors: true,
|
14 | warnings: true,
|
15 | errorDetails: true,
|
16 | chunks: false,
|
17 | colors: true
|
18 | };
|
19 | if (err) {
|
20 | console.error(err.stack || err);
|
21 | if (err.details) {
|
22 | console.error(err.details);
|
23 | }
|
24 | }
|
25 | if (stats.hasErrors() || stats.hasWarnings()) {
|
26 | options['modules'] = true;
|
27 | options['children'] = true;
|
28 | options['chunks'] = true;
|
29 | }
|
30 | console.log(stats.toString(options));
|
31 | if (stats.hasErrors()) console.log(chalk.red('❌ Compiled failed'))
|
32 | else if (stats.hasWarnings()) console.log(chalk.yellow('⚠️ Compile with warnings'))
|
33 | else console.log(chalk.green('😄 Compile successful'))
|
34 | }
|
35 | if (program.watch || cfg.webpack.watch) {
|
36 | const watching = compiler.watch(
|
37 | Object.assign(cfg.webpack.watchOptions || {},
|
38 | { aggregateTimeout: 300, poll: undefined }
|
39 | ),(err, stats) => {
|
40 | callback(err, stats)
|
41 | })
|
42 | } else {
|
43 | compiler.run((err, stats) => {
|
44 | callback(err, stats)
|
45 | });
|
46 | }
|
47 | };
|