-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
72 lines (59 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
var gulp = require('gulp'),
concat = require('gulp-concat'),
imageDataURI = require('gulp-image-data-uri'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'); // $ npm i -D imagemin-pngquant
svg2png = require('gulp-svg2png');
gulp.task('svgmin', function() {
return gulp.src('./src/assets/svg/**/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
}))
.pipe(gulp.dest('./dist/assets/svg'));
});
/**
* Convert svgs to pngs
*/
gulp.task('svg2png', ['svgmin'], function () {
return gulp.src('./src/assets/svg/**/*.svg')
.pipe(svg2png())
.pipe(gulp.dest('./temp/assets/png'));
});
gulp.task('pngmin', ['svg2png'], function() {
return gulp.src('./temp/assets/png/**/*')
.pipe(imagemin({
progressive: true,
use: [pngquant()]
}))
.pipe(gulp.dest('./dist/assets/png'));
});
/**
* Convert images to data-uris and
* concatenate them into .scss files.
* The tasks for svg and png are
* separate because they require a
* different .hbs template and
* outputted file.
*/
gulp.task('data-uri-svg', ['pngmin'], function() {
return gulp.src('./src/assets/svg/**/*.svg')
.pipe(imageDataURI({
template: {
file: './src/templates/data-uri-template-svg.hbs'
}
}))
.pipe(concat('data-uri-svg.scss'))
.pipe(gulp.dest('./dist/data-uris'));
});
gulp.task('data-uri-png', ['pngmin'], function() {
return gulp.src('./dist/assets/png/**/*.png')
.pipe(imageDataURI({
template: {
file: './src/templates/data-uri-template-png.hbs'
}
}))
.pipe(concat('data-uri-png.scss'))
.pipe(gulp.dest('./dist/data-uris'));
});
gulp.task('default', ['data-uri-svg', 'data-uri-png']);