-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (85 loc) · 2.81 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
// Gulp tasks for HTML Starter Kit
// Load plugins
var gulp = require('gulp'),
gutil = require('gulp-util'),
watch = require('gulp-watch'),
prefix = require('gulp-autoprefixer'),
size = require('gulp-size'),
rename = require('gulp-rename'),
imagemin = require('gulp-imagemin'),
minifyCSS = require('gulp-minify-css'),
sass = require('gulp-sass'),
csslint = require('gulp-csslint'),
browserSync = require('browser-sync'),
browserReload = browserSync.reload;
// Minify all css files in the css directory
// Run this in the root directory of the project with `gulp minify-css `
gulp.task('minify-css', function(){
gulp.src('./css/style.css')
.pipe(minifyCSS())
.pipe(rename('style.min.css'))
.pipe(size({gzip:true, showFiles: true}))
.pipe(gulp.dest('./css/'));
});
gulp.task('minify-img', function(){
gulp.src('./img/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
}))
.pipe(gulp.dest('./img/'));
});
// Use csslint without box-sizing or compatible vendor prefixes (these
// don't seem to be kept up to date on what to yell about)
gulp.task('csslint', function(){
gulp.src('./css/style.css')
.pipe(csslint({
'compatible-vendor-prefixes': false,
'box-sizing': false,
'important': false,
'known-properties': false
}))
.pipe(csslint.reporter());
});
// Task that compiles scss files down to good old css
gulp.task('pre-process', function(){
gulp.src('./sass/style.scss')
.pipe(watch(function(files) {
return files.pipe(sass())
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true}))
.pipe(size({gzip: true, showFiles: true}))
.pipe(gulp.dest('css'))
.pipe(minifyCSS())
.pipe(rename('style.min.css'))
.pipe(size({gzip: false, showFiles: true}))
.pipe(size({gzip: true, showFiles: true}))
.pipe(gulp.dest('./css/'))
.pipe(browserSync.reload({stream:true}));
}));
});
// Initialize browser-sync which starts a static server also allows for
// browsers to reload on filesave
gulp.task('browser-sync', function() {
browserSync.init(null, {
server: {
baseDir: "./"
}
});
});
// Function to call for reloading browsers
gulp.task('bs-reload', function () {
browserSync.reload();
});
/*
DEFAULT TASK
• Process sass then auto-prefixes and lints outputted css
• Starts a server on port 3000
• Reloads browsers when you change html or sass files
*/
gulp.task('default', ['pre-process', 'bs-reload', 'browser-sync'], function(){
gulp.start('pre-process', 'csslint', 'minify-img');
gulp.watch('sass/*.scss', ['pre-process']);
gulp.watch('css/style.css', ['bs-reload']);
gulp.watch('*.html', ['bs-reload']);
});