text: 'use strict';
  
  var gulp = require('gulp'),
      changed = require('gulp-changed'),
      sass = require('gulp-sass'),
      csso = require('gulp-csso'),
      autoprefixer = require('gulp-autoprefixer'),
      browserify = require('browserify'),
      watchify = require('watchify'),
      source = require('vinyl-source-stream'),
      buffer = require('vinyl-buffer'),
      babelify = require('babelify'),
      uglify = require('gulp-uglify'),
      del = require('del'),
      notify = require('gulp-notify'),
      browserSync = require('browser-sync'),
      sourcemaps = require('gulp-sourcemaps'),
      reload = browserSync.reload,
      p = {
        jsx: './scripts/app.jsx',
        scss: ['styles/main.scss', 'styles/components/*.scss'],
        bundle: 'app.js',
        distJs: 'dist/js',
        distCss: 'dist/css'
      };
  
  gulp.task('clean', function(cb) {
    del(['dist'], cb);
  });
  
  gulp.task('browserSync', function() {
    browserSync({
      server: {
        baseDir: './'
      }
    });
  });
  
  gulp.task('watchify', function() {
    var bundler = watchify(browserify(p.jsx, watchify.args));
  
    function rebundle() {
      return bundler
        .bundle()
        .on('error', notify.onError())
        .pipe(source(p.bundle))
        .pipe(gulp.dest(p.distJs))
        .pipe(reload({stream: true}));
    }
  
    bundler.transform("babelify", {presets: ["es2015", "react"]})
    .on('update', rebundle);
    return rebundle();
  });
  
  gulp.task('browserify', function() {
    browserify(p.jsx)
      .transform("babelify", {presets: ["es2015", "react"]})
      .bundle()
      .pipe(source(p.bundle))
      .pipe(buffer())
      .pipe(sourcemaps.init({loadMaps: true}))
      .pipe(uglify())
      .pipe(sourcemaps.write('./'))
      .pipe(gulp.dest(p.distJs));
  });
  
  gulp.task('styles', function() {
    return gulp.src(p.scss)
      .pipe(changed(p.distCss))
      .pipe(sass({errLogToConsole: true}))
      .on('error', notify.onError())
      .pipe(autoprefixer('last 1 version'))
      .pipe(csso())
      .pipe(gulp.dest(p.distCss))
      .pipe(reload({stream: true}));
  });
  
  gulp.task('fonts', function() {
    return gulp.src('node_modules/font-awesome/fonts/*')
      .pipe(gulp.dest('dist/fonts'));
  });
  
  gulp.task('watchTask', function() {
    gulp.watch(p.scss, ['styles']);
  });
  
  gulp.task('watch', ['clean', 'browserSync', 'watchTask', 'watchify', 'styles', 'fonts'], function() {
    //gulp.start(['browserSync', 'watchTask', 'watchify', 'styles', 'fonts']);
  });
  
  gulp.task('build', function() {
    process.env.NODE_ENV = 'production';
    gulp.start(['clean', 'browserify', 'styles']);
  });
  
  gulp.task('default', function() {
    console.log('Run "gulp watch or gulp build"');
  });
  