-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (92 loc) · 2.74 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
108
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var sourcemaps = require('gulp-sourcemaps');
var del = require('del');
var jade = require('gulp-jade');
var paths = {
scripts: ['src/js/**/*.coffee'],
images: ['src/**/*.png', 'src/**/*.ico'],
vendor: 'bower_components/**/*.js',
templates: 'src/**/*.jade'
};
gulp.task('clean', function(cb) {
del(['dst'], cb);
});
gulp.task('scripts', [], function() {
return gulp.src(paths.scripts)
.pipe(coffee())
.pipe(uglify())
.pipe(concat('all.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dst/js'));
});
gulp.task('scripts_dev', [], function() {
return gulp.src(paths.scripts)
.pipe(sourcemaps.init())
.pipe(coffee())
.pipe(concat('all.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dst/js'));
});
gulp.task('vendor', [], function() {
return gulp.src( paths.vendor )
.pipe(gulp.dest('dst/js/'));
});
// Copy all static images
gulp.task('images', [], function() {
return gulp.src(paths.images)
// Pass in options to the task
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest('dst'));
});
// Copy all templates
gulp.task('templates', [], function() {
return gulp.src(paths.templates)
.pipe(jade({
pretty: true
}))
.pipe(gulp.dest('dst'));
});
// execute server
gulp.task('express_dev', function() {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({port: 4002}));
app.use(express.static(__dirname + '/dst'));
app.listen(4000);
});
gulp.task('express', function() {
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/dst'));
app.listen(8080);
});
// Live reload
var tinylr;
gulp.task('livereload', function() {
tinylr = require('tiny-lr')();
tinylr.listen(4002);
});
function notifyLiveReload(event) {
var fileName = require('path').relative(__dirname, event.path);
setTimeout(function(){
tinylr.changed({
body: {
files: [fileName]
}
});
}, 100)
}
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, function( event ){ gulp.run('scripts'); notifyLiveReload(event); });
gulp.watch(paths.images, function( event ){ gulp.run('images'); notifyLiveReload(event); });
gulp.watch(paths.templates, function( event ){ gulp.run('templates'); notifyLiveReload(event); });
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['scripts', 'vendor', 'images', 'templates']);
gulp.task('dev', ['express_dev', 'livereload', 'default', 'scripts_dev', 'watch']);
gulp.task('serve', ['express', 'default']);