-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
52 lines (41 loc) · 1.07 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
var gulp = require('gulp'),
express = require('express'),
lr = require('tiny-lr')(),
open = require("gulp-open");
var EXPRESS_PORT = 4000;
var EXPRESS_ROOT = __dirname;
var LIVERELOAD_PORT = 35729;
function startExpress() {
var app = express();
app.use(require('connect-livereload')());
app.use(express.static(EXPRESS_ROOT));
app.listen(EXPRESS_PORT);
}
function startLivereload() {
lr.listen(LIVERELOAD_PORT);
}
// Notifies livereload of changes detected
// by `gulp.watch()`
function notifyLivereload(event) {
// `gulp.watch()` events provide an absolute path
// so we need to make it relative to the server root
var fileName = require('path').relative(EXPRESS_ROOT, event.path);
lr.changed({
body: {
files: [fileName]
}
});
}
gulp.task("open", function() {
var options = {
url: "http://localhost:" + EXPRESS_PORT
};
gulp.src("./index.html")
.pipe(open("", options));
});
gulp.task('default', function () {
startExpress();
startLivereload();
gulp.start("open");
gulp.watch('*.html', notifyLivereload);
});