-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
101 lines (91 loc) · 2.61 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var notifier = require('node-notifier');
var uglify = require('gulp-uglify');
var sequence = require('run-sequence');
var util = require('gulp-util');
var rename = require('gulp-rename');
var neat = require('node-neat').includePaths;
var path = require('path');
var browserSync = require('browser-sync');
// we'd need a slight delay to reload browsers
// connected to browser-sync after restarting nodemon
var BROWSER_SYNC_RELOAD_DELAY = 1000;
// Standard error handler
function standardHandler(err) {
// Notification
notifier.notify({
message: 'Error: ' + err.message
});
// Log to console
util.log(util.colors.red('Error'), err.message);
}
function sassErrorHandler(err) {
standardHandler({
message: err
});
}
gulp.task('lint', function () {
gulp.src('./**/*.js')
.pipe(jshint())
})
gulp.task('styles', function() {
util.log('Building Styles');
return gulp.src('public/css/main.scss')
.pipe(sourcemaps.init())
.pipe(sass({
onError: sassErrorHandler,
includePaths: ['styles'].concat(neat)
}))
.pipe(sourcemaps.write())
.pipe(rename(function(path) {
path.dirname = "public/css/";
path.basename = "main";
path.extname = ".less"
}))
.pipe(gulp.dest('./'));
});
gulp.task('watch', function() {
console.log('watching')
gulp.watch('public/css/**/*.scss', ['styles']);
});
gulp.task('nodemon', function (cb) {
var called = false;
return nodemon({
script: 'app.js',
ext: 'html js',
watch: ["views/", "public/css/*", "app.js", "lib/"],
})
.on('start', function onStart() {
// ensure start only got called once
if (!called) { cb(); }
called = true;
})
.on('change', ['styles'])
.on('restart', function () {
console.log('restarting');
setTimeout(function reload() {
browserSync.reload({
stream: false
});
}, BROWSER_SYNC_RELOAD_DELAY);
})
});
// Make sure `nodemon` is started before running `browser-sync`.
gulp.task('browser-sync', ['nodemon'], function() {
var port = process.env.PORT || 3000;
browserSync.init({
// see http://www.browsersync.io/docs/options/
files: ['public/**/*.*'],
proxy: 'http://localhost:' + port, // Tells BrowserSync on where the express app is running
port: 4000, // This port should be different from the express app port
open: false
});
});
gulp.task('default', function(done) {
sequence('watch', 'browser-sync', done);
});