This repository was archived by the owner on May 8, 2024. It is now read-only.
forked from milankinen/livereactload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
66 lines (56 loc) · 1.73 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
"use strict";
var gulp = require("gulp"),
gutil = require("gulp-util"),
nodemon = require("gulp-nodemon"),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
browserify = require("browserify"),
watchify = require("watchify"),
babelify = require("babelify"),
envify = require("envify"),
lrload = require("livereactload")
var isProd = process.env.NODE_ENV === "production"
function createBundler(useWatchify) {
return browserify({
entries: [ "./site.js" ],
transform: [ [babelify, {}], [envify, {}] ],
plugin: isProd || !useWatchify ? [] : [ lrload ], // no additional configuration is needed
debug: !isProd,
cache: {},
packageCache: {},
fullPaths: !isProd // for watchify
})
}
gulp.task("bundle:js", function() {
var bundler = createBundler(false)
bundler
.bundle()
.pipe(source("bundle.js"))
.pipe(gulp.dest("."))
})
gulp.task("watch:js", function() {
// start JS file watching and rebundling with watchify
var bundler = createBundler(true)
var watcher = watchify(bundler)
rebundle()
return watcher
.on("error", gutil.log)
.on("update", rebundle)
function rebundle() {
gutil.log("Update JavaScript bundle")
watcher
.bundle()
.on("error", gutil.log)
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(gulp.dest("."))
}
})
gulp.task("watch:server", function() {
nodemon({ script: "server.js", ext: "js", ignore: ["gulpfile.js", "bundle.js", "node_modules/*"] })
.on("change", function () {})
.on("restart", function () {
console.log("Server restarted")
})
})
gulp.task("default", ["watch:server", "watch:js"])