-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (94 loc) · 3.02 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
const gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
csso = require('gulp-csso'),
autoprefixer = require('gulp-autoprefixer'),
babel = require('gulp-babel'),
cache = require('gulp-cache'),
fileinclude = require('gulp-file-include'),
notify = require('gulp-notify'),
path = require('path'),
plumber = require('gulp-plumber'),
config = require('./config'),
rename = require('gulp-rename'),
critical = require('critical');
imagemin = require('gulp-imagemin');
gulp.task('sass', function () {
return gulp.src('./scss/**/*.scss')
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe (sass ())
.pipe (autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], {cascade: true}))
.pipe (gulp.dest('./css'))
.pipe (browserSync.reload({stream: true}))
});
gulp.task('html', () =>
gulp
.src(path.join(config.root.dev, config.html.dev, './**/*.html'))
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(fileinclude({
prefix: '@@',
basepath: path.join(
config.root.dev,
config.html.dev,
config.html.parts,
),
}))
.pipe(gulp.dest(path.join(config.html.dist)))
.pipe(browserSync.reload({ stream: true })));
gulp.task('browser-sync', function () {
browserSync({
server: {
baseDir: './'
},
notify: false
});
});
gulp.task('imagemin', function() {
gulp.src('./img/*')
.pipe(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
]))
.pipe(imagemin())
.pipe(gulp.dest('./img'))
})
gulp.task('critical', function(cb) {
critical.generate({
inline: true,
base: './',
src: 'index.html',
dest: 'index.html',
minify: true,
});
});
gulp.task('babel', () =>
gulp.src('js/*.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(gulp.dest('js/dist'))
);
gulp.task('cssmin', function () {
return gulp.src('./css/styles.css')
.pipe(csso())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./css/'));
});
gulp.task('watch', ['browser-sync'], function () {
gulp.watch('./scss/**/*.scss', ['sass']);
gulp.watch('./js/.*js', ['babel'], browserSync.reload);
gulp.watch('./html/**/*.html', ['html']);
gulp.watch('./js/*.js', browserSync.reload);
gulp.watch('./css/*.css', ['cssmin']);
gulp.watch('./css/styles.min.css', browserSync.reload);
gulp.watch('./css/styles.min.css', ['critical']);
});