-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
90 lines (75 loc) · 2.04 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
// imports
const gulp = require('gulp');
const embedSvg = require('gulp-embed-svg');
const srcmaps = require('gulp-sourcemaps');
const imagemin = require('gulp-imagemin');
const webp = require('gulp-webp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
// config
const AUTOPREFIXER_BROWSERS = ['> 1%', 'last 2 versions'];
// tasks
gulp.task('html', () => {
return gulp
.src('src/public/*.html')
.pipe(embedSvg({ root: './dist/public/media' }))
.pipe(gulp.dest('dist/public'));
});
gulp.task('sass', () => {
return gulp
.src('src/public/sass/*.scss')
.pipe(srcmaps.init())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe(srcmaps.write())
.pipe(gulp.dest('dist/public'));
});
const images = () => {
// gulp.src('src/public/media/**/*.png')
// .pipe(imagemin())
// .pipe(gulp.dest('dist/public/media'));
return (
gulp
.src([
'src/public/media/**/*.png',
'src/public/media/**/*.jpg',
'src/public/media/**/*.jpeg'
])
// .pipe(imagemin())
// .pipe(webp())
.pipe(gulp.dest('minified-images'))
);
};
gulp.task('images', images);
const media = () => {
return gulp
.src([
'src/public/media/**/*'
// 'minfied-images/**/*.*'
// '!src/public/media/**/*.png',
// '!src/public/media/**/*.jpg',
// '!src/public/media/**/*.jpeg'
])
.pipe(gulp.dest('dist/public/media'));
};
gulp.task('media', media);
gulp.task('redirects', () => {
return gulp.src('src/_redirects').pipe(gulp.dest('dist/public'));
});
gulp.task(
'build',
gulp.parallel(gulp.series('images', 'media', 'html'), 'sass', 'redirects')
);
gulp.task(
'build-prod',
gulp.parallel(gulp.series('media', 'html'), 'sass', 'redirects')
);
gulp.task(
'default',
gulp.series('build', () => {
gulp.watch('src/public/sass/**/*.scss', gulp.series('sass'));
gulp.watch('src/public/media/**/*', gulp.series('media'));
gulp.watch('src/public/*.html', gulp.series('html'));
gulp.watch('src/_redirects', gulp.series('redirects'));
})
);