Initial attempt at using Service Worker

- Caches facebook profile pictures and static resources
- Removes django-compressor and commited bower_components
- rest fixes
This commit is contained in:
nikolark committed 2015-11-29 16:17:25 +01:00
1 parent 195c49b0fd
commit 2b5c3529d6
468 files changed
+376 -96983

No files matched your search

+32 -6
View File
@@ -4,6 +4,7 @@ var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var bowerFiles = require('main-bower-files');
var del = require('del');
var runSequence = require('run-sequence').use(gulp);
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
@@ -39,11 +40,19 @@ gulp.task('diststyles', function () {
});
gulp.task('distscripts', function () {
return gulp.src('app/js/**/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter(require('jshint-stylish')))
var vendorSources = [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/bootstrap-sass-official/vendor/assets/javascripts/bootstrap/collapse.js',
'bower_components/bootstrap-sass-official/vendor/assets/javascripts/bootstrap/dropdown.js',
'bower_components/bootstrap-sass-official/vendor/assets/javascripts/bootstrap/tooltip.js',
'bower_components/bootstrap-datepicker/js/bootstrap-datepicker.js',
'bower_components/bootstrap-datepicker/js/locales/bootstrap-datepicker.nb.js',
'bower_components/highcharts/highcharts.js',
'bower_components/underscore/underscore-min.js'
];
return gulp.src(vendorSources.concat(['app/js/**/*.js']))
.pipe($.concat('app.min.js'))
.pipe($.uglify())
.pipe($.concat('app.js'))
.pipe(gulp.dest('dist/js'))
});
@@ -75,8 +84,8 @@ gulp.task(
return gulp.src('dist/**/*').pipe($.size({title: 'build', gzip: true}));
}
);
gulp.task('default', ['clean'], function () {
gulp.start('build');
gulp.task('default', ['clean'], function (cb) {
runSequence('build', 'generate-service-worker', cb);
});
gulp.task('serve', ['styles'], function () {
@@ -98,3 +107,20 @@ gulp.task('watch', ['serve'], function () {
gulp.watch('app/js/**/*.js', ['scripts']);
gulp.watch('app/images/**/*', ['images']);
});
gulp.task('generate-service-worker', function(callback) {
var path = require('path');
var swPrecache = require('sw-precache');
var rootDir = 'dist';
var srvRootDir = '/static/'+rootDir;
gulp.src(['bower_components/sw-toolbox/sw-toolbox.js', 'app/sw/sw-toolbox-config.js'])
.pipe(gulp.dest('dist/sw'));
swPrecache.write(path.join(rootDir, 'service-worker.js'), {
staticFileGlobs: [rootDir + '/**/*.{js,html,css,png,jpg,gif}'],
stripPrefix: rootDir,
replacePrefix: srvRootDir,
importScripts: [srvRootDir + '/sw/sw-toolbox.js', srvRootDir + '/sw/sw-toolbox-config.js']
}, callback);
});