-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (59 loc) · 1.59 KB
/
gulpfile.js
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
62
63
64
65
66
67
68
69
const _ = require('lodash');
const gulp = require('gulp');
const watchify = require('watchify');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const notify = require('gulp-notify');
const server = require('./server/');
/*
* JS helpers
*/
const getJsBundler = () => {
const myOpts = {
entries: ['./src/index.js'],
debug: true,
extensions: ['.js', '.jsx'],
};
const bwsfyOpts = Object.assign({}, watchify.args, myOpts);
const bwsfy = browserify(bwsfyOpts)
.transform('babelify');
const bundler = watchify(bwsfy);
bundler.on('log', gutil.log);
return bundler;
};
const getJsPipes = () => [
source('bundle.js'),
buffer(),
sourcemaps.init({loadMaps: true}),
sourcemaps.write('./'),
gulp.dest('./server/public/'),
];
const getJsBundleFn = (bundler) => function bundleJs(done) {
const pipes = getJsPipes();
let pipeline = bundler.bundle().on('error', notify.onError({
message: 'Error: <%= error.message %>',
title: 'Bundle Error',
}));
pipeline = pipes.reduce((pipeline, pipe) => pipeline.pipe(pipe), pipeline);
if (done) pipeline.on('end', done);
};
/*
* Dev tasks
*/
function watchJs(done) {
const bundler = getJsBundler();
const bundle = getJsBundleFn(bundler);
bundler.on('update', bundle.bind(null, null));
bundle(done);
}
function startServer() {
server.start();
}
/*
* Exported tasks
*/
exports.dev = gulp.parallel(startServer, watchJs);