 
 
 # -----------------------------------------------------------------------
-#  Javascript
+#  Build Javascript and Styles using webpack
 # -----------------------------------------------------------------------
-#
-# Browserify, watch files (to incrementally rebuild)
-#
-
-buildBrowserify = (srcPath, destDir, destFile, isWatching) ->
-  args = (if isWatching then watchify.args else {})
-  args.entries = [srcPath]
-  args.extensions = ['.coffee', '.cjsx']
-  args.debug = true if isWatching
-  bundler = browserify(args)
-  bundler.transform(browserifyShim)
-  bundler.transform(cjsxify)
-
-  bundler = watchify(bundler, {}) if isWatching
-
-  bundle = ->
-    bundler
-    .bundle()
-    .on('error', handleErrors('Browserify error'))
-    .pipe(source(destFile))
-    .pipe(gulp.dest(destDir))
-
-  bundler.on('update', bundle) if isWatching
-  bundle()
-
-build = (isWatching) ->
-  destDir = './dist/'
-  destFile = 'tutor.js'
-  srcPath = './index.coffee'
-  buildBrowserify(srcPath, destDir, destFile, isWatching)
-
-buildTests = (isWatching) ->
-  destDir = './.tmp' # This is referenced in ./test/karma.config.coffee
-  destFile = 'all-tests.js'
-  srcPath = './test/all-tests.coffee'
-  buildBrowserify(srcPath, destDir, destFile, isWatching)
 
 
-buildAndTest = (shouldWatch, done) ->
-  build(shouldWatch).on 'end', ->
-    buildTests(shouldWatch).on 'end', ->
-      config =
-        configFile: __dirname + '/test/karma.config.coffee'
-        singleRun: not shouldWatch
-        proxies:
-          '/api': '/api'
-
-      if shouldWatch
-        karma.server.start(config)
-        done()
-      else
-        karma.server.start(config, done)
-
-
-gulp.task '_buildJS', ['_cleanJS'], -> build(false)
-
-gulp.task '_cleanJS', (done) ->
-  del([
-    './dist/*.json',
-    './dist/*.js'], done)
-
-
-# -----------------------------------------------------------------------
-#  Styles
-# -----------------------------------------------------------------------
-#
-# CSS, fonts, and image resources
-#
-
-gulp.task '_css', ['_cleanCSS'], ->
-  destDirCss = './dist'
-  # Build the CSS file
-  gulp.src('./resources/styles/tutor.less')
-  .pipe(less())
-  .on('error', (error) -> console.warn error.message)
-  .pipe(gulp.dest(destDirCss))
-  .pipe(livereload())
-
-gulp.task '_cleanCSS', (done) ->
-  del(['./dist/*.css'], done)
-
-gulp.task '_copyResources', ['_cleanResources'], ->
-  destDir = './dist'
-  gulp.src("./resources/images/**/*.{svg,png,jpg}")
-    .pipe(flatten())
-    .pipe(gulp.dest(destDir))
-
-gulp.task '_cleanResources', (done) ->
-  del(['./dist/**/*.{svg,png,jpg}'], done)
-
-gulp.task '_copyFonts', ['_cleanFonts'], ->
-  destDirFonts = './dist/fonts/'
-  gulp.src([
-      'bower_components/**/*.{eot,svg,png,jpg,ttf,woff,woff2}',
-      'node_modules/**/*.{eot,svg,png,jpg,ttf,woff,woff2}',
-      'resources/fonts/**/*'
-    ])
-    .pipe(flatten())
-    .pipe(gulp.dest(destDirFonts))
-
-gulp.task '_cleanFonts', (done) ->
-  del([
-    './dist/**/*.eot',
-    './dist/**/*.woff',
-    './dist/**/*.woff2',
-    './dist/**/*.ttf'], done)
-
-
-gulp.task '_styles', ['_css', '_copyResources', '_copyFonts']
+gulp.task '_build', (done) ->
+  webpack(webpackConfig, (err, stats) ->
+    throw new gutil.PluginError("webpack", err) if err
+    gutil.log("[webpack]", stats.toString({
+      # output options
+    }))
+    done()
+  )
 
 
 

gulp            = require 'gulp'
karma           = require 'karma'
connect         = require 'gulp-connect'
cors            = require 'cors'

gzip            = require 'gulp-gzip'
livereload      = require 'gulp-livereload'
coffeelint      = require 'gulp-coffeelint'
webpack         = require 'webpack'
webpackConfig   = require './webpack.config'
webpackServer   = require 'webpack-dev-server'
_ = require 'underscore'

KARMA_CONFIG =
  configFile: __dirname + '/test/karma.config.coffee'
  singleRun: false


handleErrors = (title) => (args...) =>
