diff --git a/lib/pipeline/webpackProcess.js b/lib/pipeline/webpackProcess.js index feb0dfea7..b06460e9c 100644 --- a/lib/pipeline/webpackProcess.js +++ b/lib/pipeline/webpackProcess.js @@ -96,18 +96,48 @@ class WebpackProcess extends ProcessWrapper { }; } - webpack(webpackOptions).run((err, stats) => { - if (err) { - console.error(err); - } - if (!detectErrors) { - return callback(); } - if (stats.hasErrors()) { - return callback(stats.toJson().errors.join("\n")); - } - callback(); + webpack(webpackOptions).run((err, stats) => { + async.waterfall([ + function checkStatsError(next) { + if (err) { + console.error(err); + return next(err); + } + if (!detectErrors) { + return next(); + } + if (stats.hasErrors()) { + return next( + stats.toJson(webpackOptions.stats).errors.join("\n") + ); + } + next(); + }, + function writeStatsReport(next) { + if (detectErrors) { + self._log('info', 'writing file '+ ('dist/stats.report').bold.dim); + } + fs.writeFile( + path.join(fs.dappPath('.embark'), 'stats.report'), + stats.toString(webpackOptions.stats), + next + ); + }, + function writeStatsJSON(next) { + if (detectErrors) { + self._log('info','writing file '+ ('dist/stats.json').bold.dim); + } + fs.writeFile( + path.join(fs.dappPath('.embark'), 'stats.json'), + JSON.stringify(stats.toJson(webpackOptions.stats)), + next + ); + } + ], (err) => { + callback(err); + }); }); } }