-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
72 lines (63 loc) · 1.79 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
'use strict';
var gulp = require('gulp');
var watch = require('gulp-watch');
var imagemin = require('gulp-imagemin');
var newer = require('gulp-newer');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var svgmin = require('gulp-svgmin');
var sass = require('gulp-sass');
var cssmin = require('gulp-minify-css');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var runSequence = require('run-sequence');
// paths
var imgSrc = './images/src/*';
var imgDest = './images';
var svgSrc = './images/svg-src/*';
var svgDest = './images';
var sassSrc = './scss/*';
var sassDest = './css';
gulp.task('sass', function () {
gulp.src(sassSrc)
.pipe(sourcemaps.init())
.pipe(sass({
errLogToConsole: true
}))
.pipe(autoprefixer('last 2 version'))
.pipe(sourcemaps.write())
.pipe(gulp.dest(sassDest));
});
gulp.task('cssmin', function() {
return gulp.src('./css/styles.css')
.pipe(cssmin())
.pipe(rename('styles.min.css'))
.pipe(gulp.dest(sassDest));
});
// add image minify task
gulp.task('imagemin', function() {
return gulp.src(imgSrc)
.pipe(newer(imgSrc))
.pipe(imagemin())
.pipe(gulp.dest(imgDest));
});
// add svg minify task
gulp.task('svgmin', function() {
return gulp.src(svgSrc)
.pipe(newer(svgSrc))
.pipe(svgmin())
.pipe(gulp.dest(svgDest));
});
// Run tasks without watching.
gulp.task('build', function(callback) {
runSequence('sass', 'imagemin', 'svgmin', 'cssmin', callback);
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(sassSrc, ['sass', 'cssmin']);
gulp.watch(imgSrc, ['imagemin']);
gulp.watch(svgSrc, ['svgmin']);
});
gulp.task('default', function(callback) {
runSequence('sass', 'imagemin', 'svgmin', 'cssmin', 'watch', callback);
});