-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
61 lines (57 loc) · 1.46 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
var gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var del = require('del');
var swPrecache = require('sw-precache');
gulp.task('sass', function () {
return gulp
.src('./styles/*.scss')
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulp.dest('./styles/'))
.pipe(minifyCss({}))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./styles/'));
});
gulp.task('generate-sw', function() {
var swOptions = {
staticFileGlobs: [
'./index.html',
'./images/*.{png,svg,gif,jpg}',
'./scripts/*.js',
'./styles/*.css'
],
stripPrefix: '.',
runtimeCaching: [{
urlPattern: /^https:\/\/publicdata-weather\.firebaseio\.com/,
handler: 'networkFirst',
options: {
cache: {
name: 'weatherData-v3'
}
}
}]
};
return swPrecache.write('./service-worker.js', swOptions);
});
gulp.task('serve', ['generate-sw'], function() {
gulp.watch('./styles/*.scss', ['sass']);
browserSync({
notify: false,
logPrefix: 'weatherPWA',
server: ['.'],
open: false
});
gulp.watch([
'./*.html',
'./scripts/*.js',
'./styles/*.css',
'!./service-worker.js',
'!./gulpfile.js'
], ['generate-sw'], browserSync.reload);
});
gulp.task('default', ['serve']);