-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
110 lines (97 loc) · 2.87 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
var gulp = require('gulp'),
sass = require('gulp-sass'),
rename = require('gulp-rename'),
cssmin = require('gulp-minify-css'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
scsslint = require('gulp-sass-lint'),
cache = require('gulp-cached'),
prefix = require('gulp-autoprefixer'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
minifyHTML = require('gulp-minify-html'),
size = require('gulp-size'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
plumber = require('gulp-plumber'),
deploy = require('gulp-gh-pages'),
notify = require('gulp-notify');
gulp.task('scss', function() {
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src('scss/main.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sass())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(prefix())
.pipe(rename('main.css'))
.pipe(gulp.dest('dist/css'))
.pipe(reload({stream:true}))
.pipe(cssmin())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css'))
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "dist/"
}
});
});
gulp.task('deploy', function () {
return gulp.src('dist/**/*')
.pipe(deploy());
});
gulp.task('js', function() {
gulp.src('js/*.js')
.pipe(uglify())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(concat('j.js'))
.pipe(gulp.dest('dist/js'))
.pipe(reload({stream:true}));
});
gulp.task('scss-lint', function() {
gulp.src('scss/**/*.scss')
.pipe(cache('scsslint'))
.pipe(scsslint());
});
gulp.task('minify-html', function() {
var opts = {
comments:true,
spare:true
};
gulp.src('./*.html')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('dist/'))
.pipe(reload({stream:true}));
});
gulp.task('jshint', function() {
gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('watch', function() {
gulp.watch('scss/**/*.scss', ['scss']);
gulp.watch('js/*.js', ['jshint', 'js']);
gulp.watch('./*.html', ['minify-html']);
gulp.watch('img/*', ['imgmin']);
});
gulp.task('imgmin', function () {
return gulp.src('img/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('dist/img'));
});
gulp.task('default', ['browser-sync', 'js', 'imgmin', 'minify-html', 'scss', 'watch']);