-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
62 lines (50 loc) · 1.83 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
/* eslint-env node */
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var del = require('del');
var ghPages = require('gh-pages');
var packageJson = require('./package.json');
var path = require('path');
var runSequence = require('run-sequence');
var swPrecache = require('sw-precache');
var DEV_DIR = 'app';
var DIST_DIR = 'dist';
function writeServiceWorkerFile(rootDir, handleFetch, callback) {
var config = {
cacheId: packageJson.name,
// If handleFetch is false (i.e. because this is called from generate-service-worker-dev), then
// the service worker will precache resources but won't actually serve them.
// This allows you to test precaching behavior without worry about the cache preventing your
// local changes from being picked up during the development cycle.
handleFetch: handleFetch,
logger: $.util.log,
staticFileGlobs: [
rootDir + '/**/*.{js,html,css,png,jpg,gif}'
],
stripPrefix: rootDir + '/',
// verbose defaults to false, but for the purposes of this demo, log more.
verbose: true
};
swPrecache.write(path.join(rootDir, 'service-worker.js'), config, callback);
}
gulp.task('default', ['build']);
gulp.task('build', function(callback) {
runSequence('copy-dev-to-dist', 'generate-service-worker-dist', callback);
});
gulp.task('clean', function() {
del.sync([DIST_DIR]);
});
gulp.task('gh-pages', ['build'], function(callback) {
ghPages.publish(path.join(__dirname, DIST_DIR), callback);
});
gulp.task('generate-service-worker-dev', function(callback) {
writeServiceWorkerFile(DEV_DIR, false, callback);
});
gulp.task('generate-service-worker-dist', function(callback) {
writeServiceWorkerFile(DIST_DIR, true, callback);
});
gulp.task('copy-dev-to-dist', function() {
return gulp.src(DEV_DIR + '/**')
.pipe(gulp.dest(DIST_DIR));
});