-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (97 loc) · 3.23 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
109
110
111
112
113
114
115
116
'use strict';
var pkg = require('./package.json'),
autoprefixer = require('gulp-autoprefixer'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
connect = require('gulp-connect'),
csso = require('gulp-csso'),
del = require('del'),
ghpages = require('gh-pages'),
gulp = require('gulp'),
gutil = require('gulp-util'),
path = require('path'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
source = require('vinyl-source-stream'),
stylus = require('gulp-stylus'),
through = require('through'),
uglify = require('gulp-uglify'),
isDist = process.argv.indexOf('serve') === -1,
// browserifyPlumber fills the role of plumber() when working with browserify
browserifyPlumber = function(e) {
if (isDist) throw e;
gutil.log(e.stack);
this.emit('end');
};
gulp.task('js', ['clean:js'], function() {
// see https://wehavefaces.net/gulp-browserify-the-gulp-y-way-bb359b3f9623
return browserify('src/scripts/main.js').bundle()
.on('error', browserifyPlumber)
.pipe(source('src/scripts/main.js'))
.pipe(buffer())
.pipe(isDist ? uglify() : through())
.pipe(rename('build.js'))
.pipe(gulp.dest('dist/build'))
.pipe(connect.reload());
});
gulp.task('html', ['clean:html'], function() {
return gulp.src('src/index.html')
.pipe(gulp.dest('dist'))
.pipe(connect.reload());
});
gulp.task('css', ['clean:css'], function() {
return gulp.src('src/styles/main.styl')
.pipe(isDist ? through() : plumber())
.pipe(stylus({ 'include css': true, paths: ['./node_modules'] }))
.pipe(autoprefixer({ browsers: ['last 2 versions'], cascade: false }))
.pipe(isDist ? csso() : through())
.pipe(rename('build.css'))
.pipe(gulp.dest('dist/build'))
.pipe(connect.reload());
});
gulp.task('images', ['clean:images'], function() {
return gulp.src('src/images/**/*')
.pipe(gulp.dest('dist/images'))
.pipe(connect.reload());
});
gulp.task('fonts', ['clean:fonts'], function() {
return gulp.src('src/fonts/*')
.pipe(gulp.dest('dist/fonts'))
.pipe(connect.reload());
});
gulp.task('clean', function() {
return del.sync('dist');
});
gulp.task('clean:html', function() {
return del('dist/index.html');
});
gulp.task('clean:js', function() {
return del('dist/build/build.js');
});
gulp.task('clean:css', function() {
return del('dist/build/build.css');
});
gulp.task('clean:images', function() {
return del('dist/images');
});
gulp.task('clean:fonts', function() {
return del('dist/fonts');
});
gulp.task('connect', ['build'], function() {
connect.server({ root: 'dist', port: process.env.PORT || 8080, livereload: true });
});
gulp.task('watch', function() {
gulp.watch('src/**/*.html', ['html']);
gulp.watch('src/scripts/**/*.js', ['js']);
gulp.watch('src/styles/**/*.styl', ['css']);
gulp.watch('src/images/**/*', ['images']);
gulp.watch('src/fonts/*', ['fonts']);
});
gulp.task('publish', ['clean', 'build'], function(done) {
ghpages.publish(path.join(__dirname, 'dist'), { logger: gutil.log }, done);
});
// old alias for publishing on gh-pages
gulp.task('deploy', ['publish']);
gulp.task('build', ['js', 'html', 'css', 'images', 'fonts']);
gulp.task('serve', ['connect', 'watch']);
gulp.task('default', ['build']);