var gulp = require('gulp');
var nodemon = require('nodemon');
var webpack = require('webpack');
var clientConfig = require('./webpack.config');
var path = require('path');

function onBuild(cb) {
  return function(err, stats) {
    if (err)
      console.log('Error', err);
    else
      console.log(stats.toString());

    if (cb) cb();
  }
}

// Serverside (backend) tasks group
// Nothing so far!

// Clientside (frontend) tasks
gulp.task('client-watch', function() {
  // Changes within 100 ms = one rebuild
  webpack(clientConfig).watch(100, onBuild);
});

gulp.task('client-build', function(cb) {
  webpack(clientConfig).run(onBuild(cb));
});

// Group tasks

// For development - rebuilds whenever something changes
gulp.task('watch', ['client-watch']);

// For production - builds everything
gulp.task('build', ['client-build']);

// Nodemon is used. Maybe it's better to use gulp's own watch system?
gulp.task('run', ['client-watch'], function() {
  nodemon({
    execMap: {
      js: 'node'
    },
    script: path.join(__dirname, 'server/main.js'),
    ext: 'js json'
  }).on('restart', function() {
    console.log('Restarted!');
  });
});

@@ -166,16 +166,57 @@
 ath');%0A%0A
+var wpCompiler = webpack(clientConfig);%0A%0A
 function
@@ -554,47 +554,72 @@
 %0A  w
-ebpack(clientConfig).watch(100,
+pCompiler.watch(%7B%0A      aggregateTimeout: 100%0A    %7D,%0A   
  onBuild
 );%0A%7D
@@ -614,16 +614,18 @@
  onBuild
+()
 );%0A%7D);%0A%0A
@@ -668,36 +668,25 @@
 b) %7B%0A  w
-ebpack(clientConfig)
+pCompiler
 .run(onB

Fix onBuild callback for webpack watch mode, now it properly outputs what it should to the log (screen). Also microrefactor the webpack calling code.