Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): Handle build errors (#20)
- Loading branch information
1 parent
69813b3
commit 0f293a1
Showing
2 changed files
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}; |