This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
75 lines (66 loc) · 1.91 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
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var spritesmith = require('gulp.spritesmith');
var livereload = require('gulp-livereload');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var useref = require('gulp-useref');
gulp.task('default', function() {
gulp.run('imgemin', 'sprite', 'sass', 'autoprefx', 'js', 'html');
});
// compile sass
gulp.task('sass', function () {
gulp.src('./src/sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('./dist/css'))
.pipe(livereload());
});
gulp.task('sass:watch', function () {
livereload.listen();
gulp.watch('./src/sass/**/*.scss', ['sass', 'autoprefx']);
});
gulp.task('js', function () {
return gulp.src('./src/js/**/*.js')
.pipe(useref())
.pipe(gulp.dest('./dist/js/'));
});
gulp.task('html', function () {
return gulp.src('./src/**/*.html')
.pipe(useref())
.pipe(gulp.dest('./dist/'));
});
// get sprites
gulp.task('sprite', function () {
var spriteData = gulp.src('./src/img/icons/*.png')
.pipe(spritesmith({
/* this whole image path is used in css background declarations */
imgName: '../img/sprite.png',
cssName: '_icons.scss',
}));
spriteData.img.pipe(gulp.dest('./dist/img'));
spriteData.css.pipe(gulp.dest('./src/sass/'));
});
// css autoprefixer
gulp.task('autoprefx', function () {
gulp.src('./dist/css/css.css')
.pipe(autoprefixer({
browsers: ['last 10 versions'],
cascade: false
}))
.pipe(gulp.dest('./dist/css'));
});
// image optimization
gulp.task('imgemin', () => {
gulp.src('./src/img/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [
{removeViewBox: false},
{cleanupIDs: false}
],
use: [pngquant()]
}))
.pipe(gulp.dest('./dist/img'));
});