-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
108 lines (95 loc) · 2.52 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
'use strict';
var gulp = require('gulp'),
prefixer = require('gulp-autoprefixer'),
sass = require('gulp-sass'),
plumber = require('gulp-plumber'),
notify = require('gulp-notify'),
include = require("gulp-include"),
runSequence = require('run-sequence'),
rimraf = require('rimraf'),
browserSync = require('browser-sync'),
reload = browserSync.reload;
var path = {
build: {
html: 'build/',
js: 'build/js/',
style: 'build/css/',
img: 'build/img/',
fonts: 'build/fonts/',
},
watch: {
html: ['src/**/*.html'],
js: ['src/js/**/*.js'],
style: ['src/scss/**/*.scss'],
img: ['src/img/**/*.*'],
fonts: ['src/fonts/**/*.*'],
},
src: {
html: ['src/html/*.html'],
js: ['src/js/script.js'],
style: ['src/scss/style.scss'],
img: ['src/img/**/*.*'],
fonts: ['src/fonts/**/*.*'],
},
clean: 'build/'
};
var onError = function(err) {
notify.onError({
title: "Gulp error in " + err.plugin,
message: err.toString()
})(err);
this.emit('end');
};
gulp.task('webserver', function () {
browserSync({server: "./build"});
});
gulp.task('clean', function(cb) {
return rimraf(path.clean, cb);
});
gulp.task('build:html', function(){
return gulp.src(path.src.html)
.pipe(plumber({ errorHandler: onError }))
.pipe(include({hardFail: true}))
.pipe(gulp.dest(path.build.html))
.pipe(reload({stream: true}));
});
gulp.task('build:style', function () {
return gulp.src(path.src.style)
.pipe(plumber({ errorHandler: onError }))
.pipe(sass())
.pipe(prefixer({ browsers: ['last 10 versions'] }))
.pipe(gulp.dest(path.build.style))
.pipe(reload({stream: true}));
});
gulp.task('build:js', function(){
return gulp.src(path.src.js)
.pipe(plumber({ errorHandler: onError }))
.pipe(include({hardFail: true}))
.pipe(gulp.dest(path.build.js))
.pipe(reload({stream: true}));
});
gulp.task('build:fonts', function() {
return gulp.src(path.src.fonts)
.pipe(gulp.dest(path.build.fonts));
});
gulp.task('build:img', function () {
return gulp.src(path.src.img)
.pipe(gulp.dest(path.build.img));
});
gulp.task('build', [
'build:html',
'build:style',
'build:js',
'build:fonts',
'build:img',
]);
gulp.task('watch', function() {
gulp.watch(path.watch.html, ['build:html']);
gulp.watch(path.watch.style, ['build:style']);
gulp.watch(path.watch.js, ['build:js']);
gulp.watch(path.watch.img, ['build:img']);
gulp.watch(path.watch.fonts, ['build:fonts']);
});
gulp.task('default', ['clean'], function(cb){
runSequence( 'build', 'watch', 'webserver', cb);
});