Adding service worker cache

This commit is contained in:
Jeff Avallone 2018-02-10 16:08:42 -05:00
parent 97a61dc0f3
commit 40d08ddef8
5 changed files with 61 additions and 4 deletions

View File

@ -28,7 +28,8 @@
"uglifyjs-webpack-plugin": "^1.1.8",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.11.1",
"webpack-merge": "^4.1.1"
"webpack-merge": "^4.1.1",
"workbox-webpack-plugin": "^2.1.2"
},
"devDependencies": {
"http-server": "^0.11.1",

View File

@ -1 +1,2 @@
import '../../style.css';
import '../../service-worker';

11
src/service-worker.js Normal file
View File

@ -0,0 +1,11 @@
if ('serviceWorker' in navigator && process.env.NODE_ENV === 'production') {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(registration => {
console.log('SW registered:', registration);
})
.catch(registrationError => {
console.log('SW registration failed:', registrationError);
});
});
}

View File

@ -1,10 +1,15 @@
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
module.exports = merge(common, {
devtool: 'source-map',
plugins: [
new UglifyJSPlugin()
new UglifyJSPlugin(),
new WorkboxPlugin({
clientsClaim: true,
skipWaiting: true
})
]
});

View File

@ -2019,6 +2019,14 @@ fs-extra@^1.0.0:
jsonfile "^2.1.0"
klaw "^1.0.0"
fs-extra@^3.0.1:
version "3.0.1"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/fs-extra/-/fs-extra-3.0.1.tgz#3794f378c58b342ea7dbbb23095109c4b3b62291"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^3.0.0"
universalify "^0.1.0"
fs-write-stream-atomic@^1.0.8:
version "1.0.10"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9"
@ -2122,7 +2130,7 @@ glob-parent@^3.1.0:
is-glob "^3.1.0"
path-dirname "^1.0.0"
glob@^7.0.3, glob@^7.0.5, glob@^7.1.2:
glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2:
version "7.1.2"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
dependencies:
@ -2912,6 +2920,12 @@ jsonfile@^2.1.0:
optionalDependencies:
graceful-fs "^4.1.6"
jsonfile@^3.0.0:
version "3.0.1"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/jsonfile/-/jsonfile-3.0.1.tgz#a5ecc6f65f53f662c4415c7675a0331d0992ec66"
optionalDependencies:
graceful-fs "^4.1.6"
jsonify@~0.0.0:
version "0.0.0"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
@ -3059,7 +3073,7 @@ lodash.memoize@^4.1.2:
version "4.1.2"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
lodash.template@^4.2.4:
lodash.template@^4.2.4, lodash.template@^4.4.0:
version "4.4.0"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/lodash.template/-/lodash.template-4.4.0.tgz#e73a0385c8355591746e020b99679c690e68fba0"
dependencies:
@ -5768,6 +5782,10 @@ unique-slug@^2.0.0:
dependencies:
imurmurhash "^0.1.4"
universalify@^0.1.0:
version "0.1.1"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
unpipe@1.0.0, unpipe@~1.0.0:
version "1.0.0"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
@ -6078,6 +6096,27 @@ wordwrap@~0.0.2:
version "0.0.3"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
workbox-build@^2.1.2:
version "2.1.2"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/workbox-build/-/workbox-build-2.1.2.tgz#5425094a83ac77c991b6060dd1df3d37984ef87e"
dependencies:
chalk "^1.1.3"
fs-extra "^3.0.1"
glob "^7.1.1"
lodash.template "^4.4.0"
mkdirp "^0.5.1"
workbox-sw "^2.1.2"
workbox-sw@^2.1.2:
version "2.1.2"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/workbox-sw/-/workbox-sw-2.1.2.tgz#8f3a687c36f3b92ac2a66a08183bd3a163474b61"
workbox-webpack-plugin@^2.1.2:
version "2.1.2"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/workbox-webpack-plugin/-/workbox-webpack-plugin-2.1.2.tgz#e9d8d5cb70d5b32d5e86e92e3d099ac54c95914a"
dependencies:
workbox-build "^2.1.2"
worker-farm@^1.5.2:
version "1.5.2"
resolved "http://nexus.home.bromidic.net:8081/repository/npm-all/worker-farm/-/worker-farm-1.5.2.tgz#32b312e5dc3d5d45d79ef44acc2587491cd729ae"