-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGulpfile.js
79 lines (73 loc) · 1.82 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
70
71
72
73
74
75
76
77
78
79
// ////////////////////////////////////
// Simple task to update our views //
// ////////////////////////////////////
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
const bs = require('browser-sync').create();
const openBrowser = require('open');
// our browser-sync config + nodemon chain
gulp.task('browser-sync', ['nodemon'], () => {
// without proxy
// bs.init({
// host: 'localhost',
// port: '3001',
// open: false,
// notify: false
// });
// proxy
bs.init({
proxy: 'http://localhost:3000',
port: 4000,
open: false,
notify: false
});
});
// the real stuff
gulp.task('default', ['browser-sync'], () => {
// gulp.watch('./views/**/*.hbs', bs.reload);
gulp.watch('./public/**/*.js', bs.reload);
gulp.watch('./public/css/**/*.css', bs.reload);
gulp.watch(['./routes/**/*.js', './app.js', './bin/www', './views/**/*.hbs'], ['bs-delay']);
setTimeout(() => openBrowser('http://localhost:4000'), 1000);
});
// give nodemon time to restart
gulp.task('bs-delay', () => {
setTimeout(() => {
bs.reload({ stream: false });
}, 1000);
});
// our gulp-nodemon task
gulp.task('nodemon', (cb) => {
let started = false;
return nodemon({
script: './bin/www',
ext: 'js,hbs',
ignore: ['public/**/*.js'],
env: {
PORT: 3000,
NODE_ENV: 'development',
DEBUG: 'notes-app:*'
}
}).on('start', () => {
// avoid nodemon being started multiple times
if (!started) {
cb();
started = true;
}
})
.on('crash', () => {
// console.log('nodemon.crash');
})
.on('restart', () => {
// setTimeout(() => {
// bs.reload({
// stream: false
// });
// }, 1000);
// console.log('nodemon.restart');
})
.once('quit', () => {
// handle ctrl+c without a big weep
process.exit();
});
});