<commit_before>var gulp = require('gulp'),
    path = require('path'),
    gutil = require('gulp-util'),
    sass = require('gulp-sass'),
    webpack = require('webpack'),
    babelLoader = require('babel-loader');

var BUILD = process.env.NODE_ENV === 'production'; 

if( ! BUILD ) {
  var browserSync = require('browser-sync').create(),
      reload = browserSync.reload,
      nodemon = require('nodemon');
}

gulp.task('default',['serve'],function() {});

gulp.task('build',['sass','webpack'],function() { return gutil.log("Completed"); });

gulp.task('webpack',function(callback) {
  var init = false;

  webpack({
    entry : './static/js/index.js',

    output : {
      publicPath: '/dist/js/',
      path : path.join(__dirname, 'static/dist/js'),
      filename : 'bundle.js'
    },

    watch : !BUILD,
    devtool : BUILD ? '' : '#source-map',

    resolve : { 
      alias : {
        fs : 'browserify-fs'
      }
    },

    node : {
      process: true
    },

    module : {
      loaders : [
        { test: /\.js$/, loader: 'babel-loader', exclude: /(node_modules)/ }
      ]
    },

    plugins : BUILD ? [ new webpack.optimize.UglifyJsPlugin({ sourceMap: false }) ] : []

  }, function( err, stats ) {
    if(err) throw new gutil.PluginError('webpack',err);
    gutil.log("[webpack]",stats.toString({
      cached: false,
      colors: true
    }));
    if(!BUILD) reload();
    if(!init) { callback(); init = true; }
  });
});

gulp.task('sass',function() {
  var stream = gulp.src('./static/sass/**/*.scss')
    .pipe(sass({
      outputStyle : BUILD ? 'compressed' : 'nested'
    })).on('error', sass.logError)
    .pipe(gulp.dest('./static/style'));
    
    if(!BUILD) return stream.pipe(reload({stream:true}));
    else return stream;
});

gulp.task('serve',['nodemon','webpack'],function() {
  browserSync.init(null,{
    proxy : 'http://localhost:3000',
    port : 7000
  });
<commit_msg>Better webpack error handling<commit_after>var gulp = require('gulp'),
    path = require('path'),
    gutil = require('gulp-util'),
    sass = require('gulp-sass'),
    webpack = require('webpack'),
    babelLoader = require('babel-loader');

var BUILD = process.env.NODE_ENV === 'production'; 

if( ! BUILD ) {
  var browserSync = require('browser-sync').create(),
      reload = browserSync.reload,
      nodemon = require('nodemon');
}

gulp.task('default',['serve'],function() {});

gulp.task('build',['sass','webpack'],function() { return gutil.log("Completed"); });

gulp.task('webpack',function(callback) {
  var init = false;

  webpack({
    entry : './static/js/index.js',

    output : {
      publicPath: '/dist/js/',
      path : path.join(__dirname, 'static/dist/js'),
      filename : 'bundle.js'
    },

    watch : !BUILD,
    devtool : BUILD ? '' : '#source-map',

    resolve : { 
      alias : {
        fs : 'browserify-fs'
      }
    },

    node : {
      process: true
    },

    module : {
      loaders : [
        { test: /\.js$/, loader: 'babel-loader', exclude: /(node_modules)/ }
      ]
    },

    plugins : BUILD ? [ new webpack.optimize.UglifyJsPlugin({ sourceMap: false }) ] : []

  }, function( err, stats ) {
    if(err) throw new gutil.PluginError('webpack',err);

    var jsonStats = stats.toJson();
    if(jsonStats.errors.length > 0) 
      jsonStats.errors.forEach(function(error) {
        gutil.log(gutil.colors.magenta('webpack'),gutil.colors.bold.red('error'),error);
      });
    if(jsonStats.warnings.length > 0) 
      jsonStats.warnings.forEach(function(warning) { 
        gutil.log(gutil.colors.magenta('webpack'),gutil.colors.bold.yellow('warning'),warning);
      });

    if(!BUILD) reload();
    if(!init) { callback(); init = true; }
  });
});

gulp.task('sass',function() {
  var stream = gulp.src('./static/sass/**/*.scss')
    .pipe(sass({
      outputStyle : BUILD ? 'compressed' : 'nested'
    })).on('error', sass.logError)
    .pipe(gulp.dest('./static/style'));
    
    if(!BUILD) return stream.pipe(reload({stream:true}));
    else return stream;
});

gulp.task('serve',['nodemon','webpack'],function() {
  browserSync.init(null,{
    proxy : 'http://localhost:3000',
    port : 7000
  });

{'fraction_non_alphanumeric': 0.19923371647509577, 'fraction_numerical': 0.004310344827586207, 'mean_word_length': 2.933145009416196, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1814212', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1378, 'n_words': 235}