aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.babel.js
blob: bb0e8b5e0d352f8a467f3b40d5f1b826b10e0fa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import gulp from 'gulp';
import babel from 'gulp-babel';
import cp from 'child_process';
import gutil from 'gulp-util';
import webpack from 'webpack';
import webpackConfig from './webpack.conf';
import WebpackDevServer from 'webpack-dev-server';


gulp.task('hugo', (cb) => {
  const args = ['-d', '../dist', '-s', 'site'];
  return cp.spawn('hugo', args, {stdio: 'inherit'}).on('close', cb);
});

gulp.task('webpack', (cb) => {
  const myConfig = Object.assign({}, webpackConfig);

  // run webpack
  webpack(myConfig, (err, stats) => {
    if (err) throw new gutil.PluginError('webpack', err);
    gutil.log('[webpack]', stats.toString({
      colors: true,
      progress: true
    }));
    cb();
  });
});

gulp.task('build', ['webpack', 'hugo']);

gulp.task('server', ['build'], (cb) => {
  gulp.watch('site/**', ['hugo']);

  const myConfig = Object.assign({}, webpackConfig);
	myConfig.devtool = 'cheap-module-eval-source-map';
	myConfig.debug = true;

  for (const key in myConfig.entry) {
    myConfig.entry[key].unshift("webpack-dev-server/client?http://localhost:3009/");
  }

  // Start a webpack-dev-server
	new WebpackDevServer(webpack(myConfig), {
    contentBase: './dist',
    publicPath: '/',
		stats: {
			colors: true
		},
		hot: false,
    proxy: {
      "/confirm/*": {
        bypass: function(req, res, proxyOptions) {
          return "/pages/confirm/index.html";
        }
      }
    }
	}).listen(3009, 'localhost', function(err) {
		if(err) throw new gutil.PluginError('webpack-dev-server', err);
		gutil.log('[webpack-dev-server]', 'http://localhost:3009/');
	});
});