Skip to content
Permalink
Browse files

fix(build): Handle build errors (#20)

  • Loading branch information...
markdalgleish committed Nov 23, 2018
1 parent 69813b3 commit 0f293a164fb9876a0f32bedc75114bf47753199e
Showing with 17 additions and 4 deletions.
  1. +1 −0 bin/cli.js
  2. +16 −4 lib/build.js
@@ -72,6 +72,7 @@ const showUsage = () => {
if (playroom.hasOwnProperty(args.command)) {
playroom[args.command](err => {
if (err) {
console.error(err);
process.exit(1);
}
});
@@ -1,12 +1,24 @@
const webpack = require('webpack');
const makeWebpackConfig = require('./makeWebpackConfig');
const noop = () => {};

module.exports = (config, callback) => {
module.exports = (config, callback = noop) => {
const webpackConfig = makeWebpackConfig(config, { production: true });

webpack(webpackConfig, (...args) => {
if (typeof callback === 'function') {
callback(...args);
webpack(webpackConfig, (err, stats) => {
// https://webpack.js.org/api/node/#error-handling
if (err) {
const errorMessage = [err.stack || err, err.details]
.filter(Boolean)
.join('/n/n');
return callback(errorMessage);
}

if (stats.hasErrors()) {
const info = stats.toJson();
return callback(info.errors.join('\n\n'));
}

return callback();
});
};

0 comments on commit 0f293a1

Please sign in to comment.
You can’t perform that action at this time.