From 70cf48cf7b75583ebbdc5d925cc1ea46fb9a6322 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Mon, 31 Aug 2015 09:20:55 -0700 Subject: [PATCH] fix manifest generation during webpack watch fix gulp debug statements during gulp should always be on --- gulpfile.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++------ package.json | 1 + 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index b5eee5417a..010e83bf65 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,3 +1,6 @@ +// enable debug for gulp +process.env.DEBUG = process.env.DEBUG || 'freecc:*'; + require('babel-core/register'); var Rx = require('rx'), gulp = require('gulp'), @@ -6,6 +9,7 @@ var Rx = require('rx'), // utils plumber = require('gulp-plumber'), notify = require('gulp-notify'), + gutil = require('gulp-util'), reduce = require('gulp-reduce-file'), sortKeys = require('sort-keys'), debug = require('debug')('freecc:gulp'), @@ -43,6 +47,7 @@ var paths = { '!public/js/bundle*', 'node_modules/', 'client/', + 'server/manifests/*.json', 'server/rev-manifest.json' ], @@ -143,7 +148,7 @@ var syncDepenedents = [ 'js', 'less', 'dependents', - 'pack-client', + 'pack-watch', 'build-manifest' ]; @@ -189,16 +194,48 @@ gulp.task('pack-client', function() { .pipe(gulp.dest(paths.manifest)); }); -gulp.task('pack-watch', function() { - return gulp.src(webpackConfig.entry) +var defaultStatsOptions = { + colors: gutil.colors.supportsColor, + hash: false, + timings: false, + chunks: false, + chunkModules: false, + modules: false, + children: true, + version: true, + cached: false, + cachedAssets: false, + reasons: false, + source: false, + errorDetails: false +}; + +gulp.task('pack-watch', function(cb) { + var called = false; + gulp.src(webpackConfig.entry) .pipe(plumber({ errorHandler: errorHandler })) .pipe(webpack(Object.assign( {}, webpackConfig, webpackOptions, { watch: true } - ))) - .pipe(gulp.dest(webpackConfig.output.path)) + ), null, function(notUsed, stats) { + if (stats) { + gutil.log(stats.toString(defaultStatsOptions)); + } + + if (!called) { + debug('webpack watch completed'); + called = true; + cb(); + } + + })) + .pipe(gulp.dest(webpackConfig.output.path)); +}); + +gulp.task('pack-watch-manifest', ['pack-watch'], function() { + return gulp.src(webpackConfig.output.path + '/bundle.js') .pipe(rev()) // copy files to public .pipe(gulp.dest(webpackConfig.output.path)) @@ -301,7 +338,9 @@ var watchDependents = [ 'dependents', 'serve', 'sync', - 'build-manifest' + 'build-manifest', + 'pack-watch', + 'pack-watch-manifest' ]; gulp.task('watch', watchDependents, function() { @@ -311,7 +350,15 @@ gulp.task('watch', watchDependents, function() { gulp.watch(paths.js, ['js', 'dependents']); gulp.watch(paths.dependents, ['dependents']); gulp.watch(paths.manifest + '/*.json', ['build-manifest-watch']); + gulp.watch(webpackConfig.output.path + '/bundle.js', ['pack-watch-manifest']); }); -gulp.task('default', ['less', 'serve', 'sync', 'watch', 'pack-watch']); +gulp.task('default', [ + 'less', + 'serve', + 'pack-watch', + 'pack-watch-manifest', + 'watch', + 'sync' +]); diff --git a/package.json b/package.json index 44833cc65d..30b00f8ef2 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "gulp-reduce-file": "0.0.1", "gulp-rev": "^6.0.1", "gulp-rev-replace": "^0.4.2", + "gulp-util": "^3.0.6", "gulp-webpack": "^1.5.0", "helmet": "~0.9.0", "helmet-csp": "^0.2.3",