Created
September 16, 2016 15:27
-
-
Save mcranston18/e957c022fd5958e8913c925e606edf03 to your computer and use it in GitHub Desktop.
ES6 babel/webpack build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var path = require('path'); | |
var gulp = require('gulp'); | |
var conf = require('./conf'); | |
var browserSync = require('browser-sync'); | |
var webpack = require('webpack-stream'); | |
var $ = require('gulp-load-plugins')(); | |
function webpackWrapper(watch, test, callback) { | |
var webpackOptions = { | |
watch: watch, | |
module: { | |
preLoaders: [{ test: /\.js$/, exclude: /node_modules/, loader: 'eslint-loader'}], | |
loaders: [{ test: /\.js$/, exclude: /node_modules/, loaders: ['ng-annotate', 'babel-loader?presets[]=es2015']}] | |
}, | |
output: { filename: 'index.module.js' } | |
}; | |
if(watch) { | |
webpackOptions.devtool = 'inline-source-map'; | |
} | |
var webpackChangeHandler = function(err, stats) { | |
if(err) { | |
conf.errorHandler('Webpack')(err); | |
} | |
$.util.log(stats.toString({ | |
colors: $.util.colors.supportsColor, | |
chunks: false, | |
hash: false, | |
version: false | |
})); | |
browserSync.reload(); | |
if(watch) { | |
watch = false; | |
callback(); | |
} | |
}; | |
var sources = [ path.join(conf.paths.src, '/app/index.module.js') ]; | |
if (test) { | |
sources.push(path.join(conf.paths.src, '/app/**/*.spec.js')); | |
} | |
return gulp.src(sources) | |
.pipe(webpack(webpackOptions, null, webpackChangeHandler)) | |
.pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/app'))); | |
} | |
gulp.task('scripts', ['env'], function () { | |
return webpackWrapper(false, false); | |
}); | |
gulp.task('scripts:watch', ['scripts'], function (callback) { | |
return webpackWrapper(true, false, callback); | |
}); | |
gulp.task('scripts:test', function () { | |
return webpackWrapper(false, true); | |
}); | |
gulp.task('scripts:test-watch', ['scripts'], function (callback) { | |
return webpackWrapper(true, true, callback); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment