-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
executable file
·113 lines (101 loc) · 3 KB
/
gulpfile.js
File metadata and controls
executable file
·113 lines (101 loc) · 3 KB
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
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
minifycss = require('gulp-minify-css'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
tape = require('gulp-tape'),
tapColorize = require('tap-colorize'),
path = require('path'),
swPrecache = require('sw-precache');
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: "./dist"
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('images', function(){
gulp.src('src/img/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('dist/img/'));
});
gulp.task('html', function(){
gulp.src('./src/**/*')
.pipe(gulp.dest('./dist'));
});
gulp.task('styles', function(){
gulp.src(['src/sass/*.scss'])
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(sass())
.pipe(autoprefixer('last 1 versions'))
.pipe(gulp.dest('dist/style/'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('dist/style/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('scripts', function(){
return gulp.src('src/js/**/*.js')
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(babel())
.pipe(gulp.dest('dist/scripts/'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('dist/scripts/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('test', function() {
return gulp.src('src/spec/*.spec.js')
.pipe(tape({
reporter: tapColorize()
}));
});
gulp.task('generate-sw', function(callback) {
var rootDir = 'dist';
swPrecache.write(path.join(rootDir, 'service-worker.js'), {
staticFileGlobs: [rootDir + '/**/*.{html,js,css,png,jpg,gif,svg,eot,ttf,woff}'],
stripPrefix: rootDir,
runtimeCaching: [{
urlPattern: /^https:\/\/ajax\.googleapis\.com\/ajax\/libs\/webfont\/1\/webfont.js/,
handler: 'cacheFirst'
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com\/s/,
handler: 'cacheFirst'
},
{
urlPattern: /^http:\/\/fonts\.gstatic\.com\/s/,
handler: 'cacheFirst'
},
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/css\?.+/,
handler: 'cacheFirst'
},
{
urlPattern: /^http:\/\/fonts\.googleapis\.com\/css\?.+/,
handler: 'cacheFirst'
}]
}, callback);
});
gulp.task('default', ['browser-sync'], function(){
gulp.watch("src/sass/**/*.scss", ['styles', 'generate-service-worker']);
gulp.watch("src/js/**/*.js", ['scripts', 'generate-service-worker']);
gulp.watch("src/**/*.html", ['html']);
});