Permalink
Browse files

feat(workbox): offline page assets (#85)

  • Loading branch information...
galvez authored and pi0 committed Aug 25, 2018
1 parent ef670b8 commit 8bc4a3bbca296f9470f6ec7b63cef1abae810932
Showing with 12 additions and 2 deletions.
  1. +1 −0 .eslintignore
  2. +3 −1 docs/modules/workbox.md
  3. +2 −0 packages/workbox/index.js
  4. +6 −1 packages/workbox/templates/sw.template.js
@@ -1,2 +1,3 @@
**/templates
**/node_modules
**/dist
@@ -23,7 +23,9 @@ workbox: {
**importScripts** (Array) - Additional scripts to be imported in service worker script. (Relative to `/`. Can be placed in `assets/` directory)
**offlinePage** (String) - Enables routing all offline requests to the specified path. (Example: `/offline`)
**offlinePage** (String) - Enables routing all offline requests to the specified path. (Example: `/offline.html`)
**offlinePageAssets** (String) - List of offline page assets to precache (Example: `['/offline.png']`)
**cachingExtensions** (String) - Loads and inserts the contents of the specified file path into the service worker script, below autogenerated calls to `workbox.precaching.*`. You may add as many extra calls as you want to this file.
@@ -73,6 +73,7 @@ function getOptions (moduleOptions) {
},
offline: true,
offlinePage: null,
offlinePageAssets: [],
_runtimeCaching: [
// Cache all _nuxt resources at runtime
// They are hashed by webpack so are safe to loaded by cacheFirst handler
@@ -116,6 +117,7 @@ function addTemplates (options) {
fileName: 'sw.template.js',
options: {
offlinePage: options.offlinePage,
offlinePageAssets: options.offlinePageAssets,
cachingExtensions: options.cachingExtensions,
routingExtensions: options.routingExtensions,
importScripts: [options.wbDst].concat(options.importScripts || []),
@@ -2,7 +2,12 @@ importScripts(<%= options.importScripts.map((i) => `'${i}'`).join(', ') %>)
workbox.precaching.precacheAndRoute([], <%= JSON.stringify(options.wbOptions, null, 2) %>)
<% if (options.offlinePage) { %>workbox.precaching.precacheAndRoute(['<%= options.offlinePage %>'])<% } %>
<% if (options.offlinePage) { %>
workbox.precaching.precacheAndRoute(['<%= options.offlinePage %>'])
<% if (options.offlinePageAssets.length) { %>
workbox.precaching.precacheAndRoute([<%= options.offlinePageAssets.map((i) => `'${i}'`).join(', ') %>])
<% } %>
<% } %>
<% if (options.cachingExtensions) { %><%= options.cachingExtensions %><% } %>
<% if (options.clientsClaim) { %>workbox.clientsClaim()<% } %>
<% if (options.skipWaiting) { %>workbox.skipWaiting()<% } %>

0 comments on commit 8bc4a3b

Please sign in to comment.