function deploy(cb) {
ghPages.publish(path.join(process.cwd(), './build'), cb);
}
exports.deploy = deploy;
// const csso = require('gulp-csso'); // минификатор
gulp.task('serve', function () {
browserSync.init({
server: {
baseDir: './build'
}
});
});
// Pug
gulp.task('pug', function () {
return gulp.src('src/pug/pages/**/*.pug')
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest('build'))
.on('end', browserSync.reload);
});
// Sass
sass.compiler = require('node-sass');
gulp.task('sass', function () {
return gulp.src('src/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(changed('build/css'))
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(autoprefixer({
Browserslist: ['last 3 versions'],
cascade: false
}))
.on('error', notify.onError({
message: 'Error: <%= error.message %>',
title: 'Error running something'
}))
.pipe(sourcemaps.write('/maps'))
.pipe(gulp.dest('build/css'))
.pipe(browserSync.reload({
stream: true
}));
});
// JS
gulp.task('scripts', function () {
return gulp.src('src/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('build/js'));
})
// Optimize images
gulp.task('img', function () {
return gulp.src('src/img/**/*.{png,jpg,jpeg,svg,gif,webp}')
.pipe(cache(imagemin([
imgCompress({
loops: 4,
min: 65,
max: 80,
quality: 'high'
}),
pngquant({
speed: 1,
quality: [0.95, 1] //lossy settings
}),
webp({
quality: 80,
preset: 'photo',
method: 6
}),
imagemin.gifsicle(),
imagemin.optipng(),
imagemin.svgo({
plugins: [{
removeViewBox: true
}]
})
])))
.pipe(gulp.dest('build/img'));
});
// Optimize images (WebP)
gulp.task('exportWebP', function () {
return gulp.src('src/img/**/*')
.pipe(imagemin([
webp({
quality: 70
})
]))
.pipe(extReplace(".webp"))
.pipe(gulp.dest('build/img'));
});
gulp.task('clear', function () {
return cache.clearAll();
})
gulp.task('watch', function () {
gulp.watch('src/sass/**/*.scss', gulp.series('sass'));
gulp.watch('src/pug/**/*.pug', gulp.series('pug'));
gulp.watch('src/js/**/*.js', gulp.series('scripts'));
gulp.watch('src/img/**/*.{png,jpg,svg,gif}', gulp.series('img'));
});
gulp.task('default', gulp.series(
gulp.parallel('pug', 'sass', 'scripts', 'img'),
gulp.parallel('watch', 'serve')
));