-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (100 loc) · 2.51 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
const gulp = require('gulp'),
uglify = require('gulp-uglifyes'),
clean = require('gulp-clean'),
responsive = require('gulp-responsive'),
cleanCSS = require('gulp-clean-css'),
gzip = require('gulp-gzip'),
babel = require('gulp-babel');
const dirs = {
dev: '.',
prod: './dist'
}
let target = dirs.prod; // DEFAULT MODE
gulp.task('compress-html', function(done){
gulp.src('./*.html')
.pipe(gzip())
.pipe(gulp.dest('./dist/'))
done();
});
gulp.task('copy-manifest', function(done){
gulp.src('./manifest.json')
.pipe(gzip())
.pipe(gulp.dest('./dist/'))
done();
});
gulp.task('copy-js', function(done){
gulp.src(['./js/*.js'])
.pipe(gulp.dest('./dist/js'))
gulp.src(['./*.js'])
.pipe(gulp.dest('./dist/'))
done();
});
gulp.task('compress-css', function(done){
gulp.src('./css/*.css')
.pipe(cleanCSS())
.pipe(gzip())
.pipe(gulp.dest('./dist/css/'));
done();
});
gulp.task('compress-js', function(done){
gulp.src('./js/*.js')
.pipe(babel())
.pipe(uglify())
.pipe(gzip())
.pipe(gulp.dest('./dist/js/'));
gulp.src('./*.js')
.pipe(babel())
.pipe(uglify())
.pipe(gzip())
.pipe(gulp.dest('./dist/'));
done();
});
gulp.task('responsive-img', function(done){
gulp.src('img_src/*.{jpg,png}')
.pipe(responsive({
'*': [
{width: 1600, rename: {suffix: '-large-2x', extname: '.webp'}, quality: 80},
{width: 800, rename: {suffix: '-large', extname: '.webp'}, quality: 60},
{width: 460, rename: {suffix: '-medium', extname: '.webp'}, quality: 60},
]
},{
// default values
withMetadata: false,
progressive: true,
errorOnEnlargement: false,
}))
.pipe(gulp.dest(`${target}/img/`))
done();
});
gulp.task('fixed-img', function(done){
gulp.src('./img_src/fixed/*')
.pipe(gulp.dest(`${target}/img/`));
done();
});
gulp.task('clean-dist', function(done){
return gulp.src('./dist/*')
.pipe(clean({read: false, force: true}))
done();
});
gulp.task('clean-img', function(done){
return gulp.src(`${target}/img/*`)
.pipe(clean({read: false, force: true}))
done();
});
gulp.task('build:dist', gulp.series(
'clean-dist',
'compress-html',
'copy-manifest',
'compress-css',
'compress-js',
'responsive-img',
'fixed-img'
));
gulp.task('build', gulp.series(
function(done){target = dirs.dev; done()},
'responsive-img',
'fixed-img'
));
gulp.task('watch', function(){
gulp.watch(['*', 'js/*.js', 'css/*.css'], gulp.series('build:dist'));
});