Skip to content

Commit

Permalink
fix(build): Handle build errors (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Nov 23, 2018
1 parent 69813b3 commit 0f293a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/cli.js
Expand Up @@ -72,6 +72,7 @@ const showUsage = () => {
if (playroom.hasOwnProperty(args.command)) {
playroom[args.command](err => {
if (err) {
console.error(err);
process.exit(1);
}
});
Expand Down
20 changes: 16 additions & 4 deletions lib/build.js
@@ -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.