-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
119 lines (106 loc) · 3.19 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
117
118
119
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var autoprefixer = require('gulp-autoprefixer');
var minify = require('gulp-minify');
var imagemin = require('gulp-imagemin');
var responsive = require('gulp-responsive');
var pngquant = require('imagemin-pngquant');
var panini = require('panini');
var debug = require('gulp-debug');
gulp.task('sass', function() {
return gulp.src("./dev/scss/*.scss")
.pipe(sass()).on('error', sass.logError)
.pipe(gulp.dest("./dist/css"))
.pipe(browserSync.stream());
});
gulp.task('compile-css', function() {
return gulp.src("./dev/scss/*.scss")
.pipe(sass())
.pipe(autoprefixer({
browsers: ['defaults', 'iOS 10.2'],
cascade: false
}))
.pipe(cleanCSS({compatibility: 'ie9'}))
.pipe(gulp.dest("./dist/css"))
});
gulp.task('compile-html', function() {
return gulp.src("./dev/pages/**/*.html")
.pipe(panini({
root: './dev/pages/',
layouts: './dev/layouts/',
partials: './dev/partials/',
data: './dev/data/'
}))
.pipe(gulp.dest("./dist"))
});
gulp.task('compile-js', function() {
return gulp.src("./dev/js/*.js")
.pipe(minify())
.pipe(gulp.dest("./dist/js"))
});
gulp.task('resize-images', function() {
return gulp.src("./dev/images/to-size/*.{png,jpg}")
.pipe(responsive({
'*.jpg': [{
width: 400,
rename: { suffix: '-400px' },
}, {
width: 800,
rename: { suffix: '-800px' },
}, {
// Compress, strip metadata, and rename original image
rename: { suffix: '-original' },
}],
'*m.png': [{
width: 400,
rename: { suffix: '-400px' },
}, {
width: 800,
rename: { suffix: '-800px' },
}, {
// Compress, strip metadata, and rename original image
rename: { suffix: '-original' },
}],
'*d.png': [{
width: 500,
rename: { suffix: '-500px' },
}, {
width: 1000,
rename: { suffix: '-1000px' },
}, {
// Compress, strip metadata, and rename original image
rename: { suffix: '-original' },
}],
}))
.pipe(imagemin([
pngquant(),
], {
verbose: true
}))
.pipe(gulp.dest("./dev/images"))
});
gulp.task('compile-images', gulp.series('resize-images', function() {
return gulp.src([
"./dev/images/*",
"!./dev/images/to-size/*"
])
.pipe(imagemin([imagemin.jpegtran({progressive: true}),{verbose: true}]))
.pipe(gulp.dest("./dist/images"))
}));
gulp.task('copy-misc', function(){
return gulp.src('./dev/favicon.ico')
.pipe(gulp.dest('./dist/'));
})
gulp.task('compile-noimg', gulp.parallel('compile-html', 'compile-css', 'compile-js', 'copy-misc'));
gulp.task('compile', gulp.parallel('compile-noimg', 'resize-images', 'compile-images'));
gulp.task('serve', gulp.series('compile-noimg', function() {
browserSync.init({
server: "./dist"
});
gulp.watch("./dev/scss/*.scss", gulp.series('sass'));
gulp.watch("./dev/**/*.html").on('change', gulp.series('compile-html', browserSync.reload)) ;
gulp.watch("./dev/js/*.js").on('change', gulp.series('compile-js', browserSync.reload));
}));
gulp.task('default', gulp.series('serve'));