Browse Source

Handling errors to properly fail builds

plugin-mode
Eli Perelman 8 years ago
parent
commit
117c9e90aa
  1. 44
      packages/neutrino/commands/build/index.js
  2. 4
      packages/neutrino/package.json

44
packages/neutrino/commands/build/index.js

@ -4,25 +4,43 @@ const getPreset = require('../../src/get-preset');
const DevServer = require('webpack-dev-server'); const DevServer = require('webpack-dev-server');
const webpack = require('webpack'); const webpack = require('webpack');
const handleErrors = (err, stats) => {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
return true;
}
const jsonStats = stats.toJson();
if (jsonStats.errors.length) {
jsonStats.errors.map(err => console.error(err));
return true;
}
return false;
};
const build = (config, done) => { const build = (config, done) => {
const compiler = webpack(config); const compiler = webpack(config);
compiler.run((err, stats) => { compiler.run((err, stats) => {
if (!err) { const failed = handleErrors(err, stats);
console.log(stats.toString({
colors: true, if (failed) {
chunks: false, return done(1);
children: false
}));
} else {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
} }
done(); console.log(stats.toString({
colors: true,
chunks: false,
children: false
}));
done(0);
}); });
}; };

4
packages/neutrino/package.json

@ -1,6 +1,6 @@
{ {
"name": "neutrino", "name": "neutrino",
"version": "2.1.0", "version": "2.2.0",
"description": "Create and build JS applications with managed configurations", "description": "Create and build JS applications with managed configurations",
"main": "bin/neutrino", "main": "bin/neutrino",
"bin": { "bin": {
@ -52,7 +52,7 @@
"resolve": "1.1.7", "resolve": "1.1.7",
"vorpal": "1.4.1", "vorpal": "1.4.1",
"webpack": "1.13.2", "webpack": "1.13.2",
"webpack-dev-server": "1.15.2", "webpack-dev-server": "1.16.2",
"webpack-hot-middleware": "2.12.2", "webpack-hot-middleware": "2.12.2",
"webpack-merge": "0.14.1", "webpack-merge": "0.14.1",
"yeoman-environment": "1.6.3" "yeoman-environment": "1.6.3"

Loading…
Cancel
Save