-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
38 lines (30 loc) · 994 Bytes
/
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
const gulp = require("gulp");
const buffer = require("vinyl-buffer");
const browserify = require("browserify");
const watchify = require("watchify");
const babel = require("babelify");
const source = require("vinyl-source-stream");
function compile(watch) {
let bundler = watchify(browserify({ entries:"client/src/index.js"}).transform(babel));
function rebundle() {
bundler.bundle()
.on("error", function(err) { console.error(err); this.emit("end"); })
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(gulp.dest("./client/dist"));
console.log("Build finished!");
}
if (watch) {
bundler.on("update", function() {
console.log("Building...");
rebundle();
});
}
rebundle();
}
function watch() {
return compile(true);
}
gulp.task("build", function() { return compile(); });
gulp.task("watch", function() { return watch(); });
gulp.task("default", ["build"]);