-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
80 lines (67 loc) · 2.08 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
80
var gulp = require('gulp');
var del = require('del');
var gulpNodemon = require('gulp-nodemon');
var appFile = './server.js';
var app = require(appFile);
var appPort = app.get('port');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var browserSyncPort = 8001;
var nodemon;
//Clean
gulp.task('clean:styles', function() {
del(['dist/styles/**/*']);
});
gulp.task('clean:scripts', function() {
del(['dist/scripts/**/*']);
});
gulp.task('clean:images', function() {
del(['dist/images/**/*']);
});
gulp.task('clean', ['clean:styles', 'clean:scripts', 'clean:images']);
//Build
gulp.task('build:styles', ['clean:styles'], function() {
return gulp.src('src/styles/**/*.css')
.pipe(gulp.dest('dist/styles/'))
.pipe(reload({stream:true}));
});
gulp.task('build:scripts', ['clean:scripts'], function() {
return gulp.src('src/scripts/**/*.js')
.pipe(gulp.dest('dist/scripts/'))
.pipe(reload({stream:true}));
});
gulp.task('build:images', ['clean:images'], function() {
return gulp.src('src/images/**/*')
.pipe(gulp.dest('dist/images/'))
.pipe(reload({stream:true}));
});
gulp.task('build', ['build:styles', 'build:scripts', 'build:images']);
//Serve
gulp.task('watch', function() {
gulp.watch('src/styles/**/*', ['build:styles']);
gulp.watch('src/scripts/**/*', ['build:scripts']);
gulp.watch('src/images/**/*', ['build:images']);
gulp.watch('views/**/*', ['bs-reload']);
gulp.watch(['routes/**/*', appFile], ['restart-server']);
});
gulp.task('serve', ['build', 'watch'], function() {
nodemon = gulpNodemon({ script: appFile, ext: 'null' });
});
gulp.task('browser-sync', ['serve'], function() {
browserSync({
proxy: "http://localhost:" + appPort,
port: browserSyncPort
});
});
//Restart server
gulp.task('restart-server', function() {
if (nodemon) {
nodemon.emit('restart');
setTimeout(function() {gulp.start('bs-reload');}, 1000);
} else gulp.start('serve');
});
//Reload all browsers
gulp.task('bs-reload', function() {
reload();
});
gulp.task('default', ['browser-sync']);