-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathGulpfile.js
94 lines (78 loc) · 2.43 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
'use strict';
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
source = require('vinyl-source-stream'),
browserify = require('browserify'),
concat = require('gulp-concat'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
refresh = require('gulp-livereload'),
nodemon = require('gulp-nodemon');
var expressServer = require('./server');
gulp.task('serve_', function() {
console.log('Server');
expressServer.startServer();
});
gulp.task('serve', function () {
nodemon({ script: 'server.js', ext: 'json js', ignore: ['public/*', 'client/*'] })
.on('change', ['lint'])
.on('restart', function () {
console.log('Restarted webserver')
});
});
// Dev task
gulp.task('dev', ['views', 'styles', 'lint', 'browserify', 'watch'], function() {});
// JSLint task
gulp.task('lint', function() {
gulp.src('client/scripts/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Styles task
gulp.task('styles', function() {
gulp.src('client/styles/*.scss')
// The onerror handler prevents Gulp from crashing when you make a mistake in your SASS
.pipe(sass({onError: function(e) { console.log(e); } }))
// Optionally add autoprefixer
.pipe(autoprefixer('last 2 versions', '> 1%', 'ie 8'))
// These last two should look familiar now :)
.pipe(gulp.dest('public/css/'));
});
// Browserify task
gulp.task('browserify', function() {
var bundleStream = browserify({
entries: ['./client/scripts/main.js'],
debug: true
}).bundle().pipe(source('core.js'));
return bundleStream.pipe(gulp.dest('./public/js'));
});
// Views task
gulp.task('views', function() {
// Get our index.html
gulp.src('client/index.html')
// And put it in the public folder
.pipe(gulp.dest('public/'));
// Any other view files from client/views
gulp.src('client/views/**/*')
// Will be put in the public/views folder
.pipe(gulp.dest('public/views/'));
});
gulp.task('watch', ['serve', 'lint'], function() {
// Start live reload server
refresh.listen();
// Watch our scripts, and when they change run lint and browserify
gulp.watch(['client/scripts/*.js', 'client/scripts/**/*.js'],[
'lint',
'browserify'
]);
// Watch our sass files
gulp.watch(['client/styles/**/*.scss'], [
'styles'
]);
// Watch view files
gulp.watch(['client/**/*.html'], [
'views'
]);
gulp.watch('./public/**').on('change', refresh.changed);
});
gulp.task('default', ['dev']);