text: var gulp = require('gulp');
  var gutil = require('gulp-util');
  var gulpif = require('gulp-if');
  var autoprefixer = require('gulp-autoprefixer');
  var cssmin = require('gulp-cssmin');
  var less = require('gulp-less');
  var concat = require('gulp-concat');
  var plumber = require('gulp-plumber');
  var buffer = require('vinyl-buffer');
  var source = require('vinyl-source-stream');
  var babelify = require('babelify');
  var browserify = require('browserify');
  var watchify = require('watchify');
  var uglify = require('gulp-uglify');
  var sourcemaps = require('gulp-sourcemaps');
  
  var production = process.env.NODE_ENV === 'production';
  
  var dependencies = [
    'alt',
    'react',
    'react-dom',
    'react-router',
    'underscore'
  ];
  
  //combine all js libraries into a singler file for few http req
  gulp.task('vendor', function() {
    return gulp.src([
      'bower_components/jquery/dist/jquery.js',
      'bower_components/bootstrap/dist/js/jquery.magific-popup.js',
      'bower_components/toastr/toastr.js'
    ]).pipe(concat('vendor.js'))
      .pipe(gulpif(production, uglify({ mangle: false })))
      .pipe(gulp.dest('public/js'));
  });
  
  //compile 3rd party dependencies
  gulp.task('browserify-vendor', function() {
    return browserify()
      .require(dependencies)
      .bundle()
      .pipe(source('vendor.bundle.js'))
      .pipe(buffer())
      .pipe(gulpif(production, uglify({ mangle: false })))
      .pipe(gulp.dest('public/js'));
  });
  
  //compile project files
  gulp.task('browserify', ['browserify-vendor'], function() {
    return browserify({ entries: 'app/main.js', debug: true })
      .external(dependencies)
      .transform(babelify, { presets: ['es2015', 'react'] })
      .bundle()
      .pipe(source('bundle.js'))
      .pipe(buffer())
      .pipe(sourcemaps.init({ loadMaps: true }))
      .pipe(gulpif(production, uglify({ mangle: false })))
      .pipe(gulp.dest('public/js'));
  });
  
  //watching for project file changes and re-browserify
  gulp.task('browserify-watch', ['browserify-vendor'], function() {
    var bundler = watchify(browserify({ entries: 'app/main.js', debug: true }, watchify.args));
    bundler.external(dependencies);
    bundler.transform(babelify, { presets: ['es2015', 'react']});
    bundler.on('update', rebundle);
    return rebundle();
  
    function rebundle() {
      var start = Date.now();
      return bundler.bundle()
        .on('error', function(err) {
          gutil.log(gutil.colors.red(err.toString()));
        })
        .on('end', function() {
          gutil.log(gutil.colors.green('Finished rebundling in', (Date.now() - start) + 'ms.'));
        })
        .pipe(source('bundle.js'))
        .pipe(buffer())
        .pipe(sourcemaps.init({ loadMaps: true }))
        .pipe(gulp.dest('public/js/'));
    }
  });
  
  //compile LESS sheets
  gulp.task('styles', function() {
    return gulp.src('app/stylesheets/main.less')
      .pipe(plumber())
      .pipe(less())
      .pipe(autoprefixer())
      .pipe(gulpif(production, cssmin()))
      .pipe(gulp.dest('public/css'));
  });
  
  gulp.task('watch', function() {
    gulp.watch('app/stylesheets/**/*.less', ['styles']);
  });
  
  gulp.task('default', ['styles', 'vendor', 'browserify-watch', 'watch']);
  gulp.task('build', ['styles', 'vendor', 'browserify']);
  