-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (100 loc) · 3.21 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
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
cache = require('gulp-cache'),
cmq = require('gulp-combine-media-queries'),
livereload = require('gulp-livereload'),
del = require('del'),
critical = require('critical');
// load plugins
var $ = require('gulp-load-plugins')();
// Styles
gulp.task('styles', function() {
return sass('src/sass', { style: 'expanded' })
.pipe(gulp.dest('dist/style'))
.pipe(cmq({ log: false }))
.pipe(gulp.dest('dist/style'))
.pipe(autoprefixer('last 3 version'))
.pipe(gulp.dest('dist/style'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest('dist/style'))
.pipe(notify({ message: 'Stylish' }));
});
gulp.task('images', function() {
return gulp.src('src/img/**/*')
.pipe(cache(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true })))
.pipe(gulp.dest('dist/img'))
.pipe(notify({ message: 'Images task complete' }));
});
gulp.task('scripts', function() {
return gulp.src('src/js/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(gulp.dest('dist/scripts'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts'))
.pipe(notify({ message: 'Javascripts, woo!' }));
});
//copies the html to the dist folder
gulp.task('html', function () {
return gulp.src('src/html/**/*.html')
.pipe(gulp.dest('dist/'))
.pipe(notify({ message: 'HTML'}));
});
gulp.task('copystyles', function () {
return gulp.src(['style/main.css'])
.pipe($.rename({
basename: "site"
}))
.pipe(gulp.dest('style'));
});
// Generate & Inline Critical-path CSS
gulp.task('critical', ['build', 'copystyles'], function (cb) {
// At this point, we have our
// production styles in main/styles.css
// As we're going to overwrite this with
// our critical-path CSS let's create a copy
// of our site-wide styles so we can async
// load them in later. We do this with
// 'copystyles' above
critical.generate({
base: 'dist/',
src: 'index.html',
dest: 'style/site.css',
width: 320,
height: 480,
minify: true,
extract: true
}, function(err, output){
critical.inline({
base: 'dist/',
src: 'index.html',
dest: 'index-critical.html',
minify: true
});
});
});
gulp.task('build', ['scripts']);
gulp.task('clean', function(cb) {
del(['style', 'scripts', 'img'], cb)
});
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'scripts', 'images');
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch('src/sass/**/*.scss', ['styles']);
gulp.watch('src/js/**/*.js', ['scripts']);
gulp.watch('src/img/**/*', ['images']);
gulp.watch('src/html/**/*.html', ['html']);
gulp.watch('dist/style/**').on('change', livereload.changed);
});