From 51bb0bb13f3f7b63bcb46d9bdcd4390bcbfc7291 Mon Sep 17 00:00:00 2001 From: Lucia Jelinkova Date: Fri, 15 Mar 2019 14:24:02 +0100 Subject: [PATCH] Dashboard: fail build when webpack has errors Signed-off-by: Lucia Jelinkova --- dashboard/gulp/inject.js | 8 ++++++-- dashboard/gulp/scripts.js | 20 ++++++++++++-------- dashboard/gulp/watch.js | 7 ++++--- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/dashboard/gulp/inject.js b/dashboard/gulp/inject.js index 02c2adc875..45bd2a7f18 100644 --- a/dashboard/gulp/inject.js +++ b/dashboard/gulp/inject.js @@ -18,7 +18,7 @@ var conf = require('./conf'); var $ = require('gulp-load-plugins')(); -gulp.task('inject', ['outputcolors', 'proxySettings', 'scripts', 'styles'], function () { +function inject() { var injectStyles = gulp.src([ path.join(conf.paths.tmp, '/serve/app/**/*.css'), path.join('!' + conf.paths.tmp, '/serve/app/vendor.css') @@ -37,4 +37,8 @@ gulp.task('inject', ['outputcolors', 'proxySettings', 'scripts', 'styles'], func .pipe($.inject(injectStyles, injectOptions)) .pipe($.inject(injectScripts, injectOptions)) .pipe(gulp.dest(path.join(conf.paths.tmp, '/serve'))); -}); +} + +gulp.task('inject', ['outputcolors', 'proxySettings', 'scripts', 'styles'], inject); + +gulp.task('inject:watch', ['outputcolors', 'proxySettings', 'scripts:watch', 'styles'], inject); diff --git a/dashboard/gulp/scripts.js b/dashboard/gulp/scripts.js index 3c76cd60e7..020992a58c 100644 --- a/dashboard/gulp/scripts.js +++ b/dashboard/gulp/scripts.js @@ -80,20 +80,24 @@ function webpackWrapper(watch, test, callback) { webpackOptions.devtool = 'inline-source-map'; } + var callbackCalled = false; + var webpackChangeHandler = function (err, stats) { - if (err) { - conf.errorHandler('Webpack')(err); - } $.util.log(stats.toString({ colors: $.util.colors.supportsColor, chunks: false, hash: false, version: false })); - browserSync.reload(); - if (watch) { - watch = false; - callback(); + + if (!watch && stats.hasErrors()) { + $.util.log($.util.colors.red('[Webpack task failed with errors]')); + process.exit(1); + } + + if (watch && !callbackCalled) { + callbackCalled = true; + callback(); } }; @@ -111,7 +115,7 @@ gulp.task('scripts', ['colors', 'proxySettings'], function () { return webpackWrapper(false, false); }); -gulp.task('scripts:watch', ['scripts'], function (callback) { +gulp.task('scripts:watch', ['colors', 'proxySettings'], function (callback) { return webpackWrapper(true, false, callback); }); diff --git a/dashboard/gulp/watch.js b/dashboard/gulp/watch.js index d459e25fc2..eafe19ef08 100644 --- a/dashboard/gulp/watch.js +++ b/dashboard/gulp/watch.js @@ -22,9 +22,9 @@ function isOnlyChange(event) { return event.type === 'changed'; } -gulp.task('watch', ['scripts:watch', 'inject'], function () { +gulp.task('watch', ['scripts:watch', 'inject:watch'], function () { - gulp.watch([path.join(conf.paths.src, '/*.html')], ['inject']); + gulp.watch([path.join(conf.paths.src, '/*.html')], ['inject:watch']); gulp.watch([ path.join(conf.paths.src, '/app/**/*.css'), @@ -35,8 +35,9 @@ gulp.task('watch', ['scripts:watch', 'inject'], function () { if(isOnlyChange(event)) { gulp.start('styles'); } else { - gulp.start('inject'); + gulp.start('inject:watch'); } + browserSync.reload(); });