-
Notifications
You must be signed in to change notification settings - Fork 15
/
gulpfile.js
125 lines (109 loc) · 2.85 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
117
118
119
120
121
122
123
124
125
'use strict';
const gulp = require('gulp');
const gulpSequence = require('gulp-sequence');
const sass = require('gulp-sass');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const del = require('del');
const browserSync = require('browser-sync').create();
const ghPages = require('gulp-gh-pages');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const wait = require('gulp-wait');
const fileInclude = require("gulp-file-include");
let postCssPlugins = [
autoprefixer({
browsers: ['last 2 version']
}),
];
gulp.task('style', function () {
return gulp.src('src/scss/style.scss')
.pipe(plumber({
errorHandler: function(err) {
notify.onError({
title: 'Styles compilation error',
message: err.message
})(err);
this.emit('end');
}
}))
.pipe(wait(100))
.pipe(sass())
.pipe(postcss(postCssPlugins))
.pipe(gulp.dest('build/css/'))
.pipe(browserSync.stream({match: '**/*.css'}));
});
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe(fileInclude({
indent: true,
}))
.pipe(gulp.dest('build'));
});
gulp.task('copy:img', function () {
return gulp.src('src/img/**/*.{jpg,jpeg,png,svg}')
.pipe(gulp.dest('build/img'));
});
gulp.task('copy:fonts', function () {
return gulp.src('src/fonts/*.{ttf,woff,woff2,eot,svg}')
.pipe(gulp.dest('build/fonts'));
});
gulp.task('copy:js', function () {
return gulp.src('src/js/*.js')
.pipe(gulp.dest('build/js'));
});
gulp.task('copy:css', function () {
return gulp.src('src/css/*.css')
.pipe(gulp.dest('build/css'));
});
gulp.task('clean', function () {
return del([
'build/**/*',
'build/readme.md',
]);
});
gulp.task('build', function (callback) {
gulpSequence(
'clean',
['style', 'copy:img', 'copy:fonts', 'copy:js', 'copy:css'],
'html',
callback
);
});
gulp.task('default', ['serve']);
gulp.task('serve', ['build'], function() {
browserSync.init({
server: 'build',
startPath: 'index.html',
open: false,
port: 8080,
});
gulp.watch([
'src/scss/style.scss',
], ['style']);
gulp.watch([
'src/*.html',
'src/_html-include/*.html',
], ['watch:html']);
gulp.watch('src/img/**/*.{jpg,png,svg}', ['watch:img']);
gulp.watch('src/fonts/*.{ttf,woff,woff2,eot,svg}', ['watch:fonts']);
gulp.watch('src/js/*.js', ['watch:js']);
});
gulp.task('watch:html', ['html'], reload);
gulp.task('watch:img', ['copy:img'], reload);
gulp.task('watch:fonts', ['copy:fonts'], reload);
gulp.task('watch:js', ['copy:js'], reload);
gulp.task('deploy', function() {
return gulp.src('build/**/*')
.pipe(ghPages());
});
function reload (done) {
browserSync.reload();
done();
}
var onError = function(err) {
notify.onError({
title: 'Error in ' + err.plugin,
})(err);
this.emit('end');
};