-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
52 lines (45 loc) · 1.35 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
/* Thanks to http://rhumaric.com/2014/01/livereload-magic-gulp-style/ */
var gulp = require('gulp');
var EXPRESS_PORT = 9999;
var EXPRESS_ROOT = __dirname;
var LIVERELOAD_PORT = 35729;
// Let's make things more readable by
// encapsulating each part's setup
// in its own method
function startExpress() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')());
app.use(express.static(EXPRESS_ROOT));
app.listen(EXPRESS_PORT);
}
// We'll need a reference to the tinylr
// object to send notifications of file changes
// further down
var lr;
function startLivereload() {
lr = require('tiny-lr')();
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]
}
});
console.log(fileName, 'saved and', 'browser Reloaded!'.cyan)
}
// Default task that will be run
// when no parameter is provided
// to gulp
gulp.task('default', function () {
startExpress();
startLivereload();
gulp.watch('*.html', notifyLivereload);
gulp.watch('styles/*.css', notifyLivereload);
});