-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
112 lines (97 loc) · 2.94 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
'use strict';
var gulp = require('gulp'),
gp = require('gulp-load-plugins')(),
browserSync = require('browser-sync').create();
gulp.task('html', function() {
return gulp.src('src/*.html')
.pipe(gp.rigger())
.pipe(gulp.dest('build/'))
.on("error", gp.notify.onError({
message: "Error: <%= error.message %>",
title: "HTML"
}))
.on('end', browserSync.reload);
});
gulp.task('css', function() {
return gulp.src('src/scss/**/*.scss')
.pipe(gp.sourcemaps.init())
.pipe(gp.sass().on('error', gp.sass.logError))
.pipe(gp.autoprefixer({
browsers: ['last 10 versions'],
cascade: false
}))
.pipe(gp.csso())
.pipe(gp.sourcemaps.write())
.pipe(gulp.dest('build/css'))
.on("error", gp.notify.onError({
message: "Error: <%= error.message %>",
title: "CSS"
}))
.pipe(browserSync.reload({
stream: true
}));
});
gulp.task('css:build',function() {
return gulp.src('src/scss/**/*.css')
.pipe(gulp.dest('build/css'))
});
gulp.task('js:dev', function() {
return gulp.src('src/js/**/*.js')
.on("error", gp.notify.onError({
message: "Error: <%= error.message %>",
title: "CSS"
}))
.pipe(browserSync.reload({
stream: true
}))
.pipe(gulp.dest('build/js'));
});
gulp.task('js:build',function() {
return gulp.src('src/js/**/*')
.pipe(gulp.dest('build/js'))
});
gulp.task('img:dev',function() {
return gulp.src('src/img/**/*')
.pipe(gulp.dest('build/img'))
});
gulp.task('img:build',function() {
return gulp.src('src/img/**/*.{png,jpg}')
.pipe(gp.tinypng('4jyAh2TumYspKSm9bJ8td6WmPOA7MzjG'))
.pipe(gulp.dest('build/img'))
});
gulp.task('svg',function() {
return gulp.src('src/img/**/*.svg')
.pipe(gp.svgmin({
js2svg: {
pretty: true
}
}))
.pipe(gp.replace('>','>'))
.pipe(gp.svgSprite({
mode: {
symbol: {
sprite: "../sprite.svg"
}
}
}))
.pipe(gulp.dest('build/img'))
});
gulp.task('fonts:build',function() {
return gulp.src('src/fonts/**/*')
.pipe(gulp.dest('build/fonts'))
});
gulp.task('server', function() {
browserSync.init({
server: {
baseDir: './build'
}
});
});
gulp.task('watch',function() {
gulp.watch('src/**/*.html',gulp.series('html'));
gulp.watch('src/scss/**/*.scss',gulp.series('css'));
gulp.watch('src/js/**/*.js',gulp.series('js:dev'));
gulp.watch('src/img/**/*',gulp.series('img:dev'));
});
gulp.task('default',gulp.series(gulp.parallel('html','css','js:dev','img:dev'), gulp.parallel('watch','server')));
gulp.task('build',gulp.series(gulp.parallel('html','css','css:build','js:build','img:build','fonts:build','svg')));