blob: 9671b2329e4a690eb3979300feac252a6f1979d8 [file] [log] [blame]
Matteo Scandolod819c922016-12-02 14:06:14 -08001const 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
Matteo Scandolo4e870232017-01-30 13:43:05 -080023gulp.task('webpack:dist:watch', done => {
24 process.env.NODE_ENV = 'production';
25 webpackWrapper(true, webpackDistConf, done);
26});
27
Matteo Scandolod819c922016-12-02 14:06:14 -080028function webpackWrapper(watch, conf, done) {
29 const webpackBundler = webpack(conf);
30
31 const webpackChangeHandler = (err, stats) => {
32 if (err) {
33 gulpConf.errorHandler('Webpack')(err);
34 }
35 gutil.log(stats.toString({
36 colors: true,
37 chunks: false,
38 hash: false,
39 version: false
40 }));
41 if (done) {
42 done();
43 done = null;
44 } else {
45 browsersync.reload();
46 }
47 };
48
49 if (watch) {
50 webpackBundler.watch(200, webpackChangeHandler);
51 } else {
52 webpackBundler.run(webpackChangeHandler);
53 }
54}