blob: ec8e8b1c21c23387f03544a6e9644a11200f7403 [file] [log] [blame]
Matteo Scandoloc46a82d2017-03-24 18:37:18 -07001const gulp = require('gulp');
2const gutil = require('gulp-util');
3
4const webpack = require('webpack');
5const webpackConf = require('../conf/webpack.conf');
6const webpackDistConf = require('../conf/webpack-dist.conf');
7const gulpConf = require('../conf/gulp.conf');
8const browsersync = require('browser-sync');
9
10gulp.task('webpack:dev', done => {
11 webpackWrapper(false, webpackConf, done);
12});
13
14gulp.task('webpack:watch', done => {
15 webpackWrapper(true, webpackConf, done);
16});
17
18gulp.task('webpack:dist', done => {
19 process.env.NODE_ENV = 'production';
20 webpackWrapper(false, webpackDistConf, done);
21});
22
23function webpackWrapper(watch, conf, done) {
24 const webpackBundler = webpack(conf);
25
26 const webpackChangeHandler = (err, stats) => {
27 if (err) {
28 gulpConf.errorHandler('Webpack')(err);
29 }
30 gutil.log(stats.toString({
31 colors: true,
32 chunks: false,
33 hash: false,
34 version: false
35 }));
36 if (done) {
37 done();
38 done = null;
39 } else {
40 browsersync.reload();
41 }
42 };
43
44 if (watch) {
45 webpackBundler.watch(200, webpackChangeHandler);
46 } else {
47 webpackBundler.run(webpackChangeHandler);
48 }
49}