-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathGulpfile.js
107 lines (91 loc) · 2.86 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
102
103
104
105
106
107
'use strict';
var gulp = require('gulp'),
jshint = require('gulp-jshint'),
browserify = require('gulp-browserify'),
concat = require('gulp-concat'),
rimraf = require('gulp-rimraf'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer');
// Modules for webserver and livereload
var express = require('express'),
refresh = require('gulp-livereload'),
livereload = require('connect-livereload'),
livereloadport = 35729,
serverport = 5000;
// Set up an express server (not starting it yet)
var server = express();
// Add live reload
server.use(livereload({port: livereloadport}));
// Use our 'dist' folder as rootfolder
server.use(express.static('./dist'));
// Because I like HTML5 pushstate .. this redirects everything back to our index.html
server.all('/*', function(req, res) {
res.sendfile('index.html', { root: 'dist' });
});
// Dev task
gulp.task('dev', ['clean', 'views', 'styles', 'lint', 'browserify'], function() { });
// Clean task
gulp.task('clean', function() {
gulp.src('./dist/views', { read: false }) // much faster
.pipe(rimraf({force: true}));
});
// JSHint task
gulp.task('lint', function() {
gulp.src('app/scripts/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Styles task
gulp.task('styles', function() {
gulp.src('app/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('dist/css/'));
});
// Browserify task
gulp.task('browserify', function() {
// Single point of entry (make sure not to src ALL your files, browserify will figure it out)
gulp.src(['app/scripts/main.js'])
.pipe(browserify({
insertGlobals: true,
debug: false
}))
// Bundle to a single file
.pipe(concat('bundle.js'))
// Output it to our dist folder
.pipe(gulp.dest('dist/js'));
});
// Views task
gulp.task('views', function() {
// Get our index.html
gulp.src('app/index.html')
// And put it in the dist folder
.pipe(gulp.dest('dist/'));
// Any other view files from app/views
gulp.src('app/views/**/*')
// Will be put in the dist/views folder
.pipe(gulp.dest('dist/views/'));
});
gulp.task('watch', ['lint'], function() {
// Start webserver
server.listen(serverport);
// Start live reload
refresh.listen(livereloadport);
// Watch our scripts, and when they change run lint and browserify
gulp.watch(['app/scripts/*.js', 'app/scripts/**/*.js'],[
'lint',
'browserify'
]);
// Watch our sass files
gulp.watch(['app/styles/**/*.scss'], [
'styles'
]);
gulp.watch(['app/**/*.html'], [
'views'
]);
gulp.watch('./dist/**').on('change', refresh.changed);
});
gulp.task('default', ['dev', 'watch']);