Skip to content

Commit

Permalink
feat(workbox): support pass config object to workbox.setConfig (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi authored and pi0 committed Sep 21, 2018
1 parent 575f713 commit b5dab8a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/modules/workbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ workbox: {

**routingExtensions** (String) - Loads and inserts the contents of the specified file path into the service worker script, below autogenerated calls to `workbox.routing.*`. You may add as many extra calls as you want to this file.

**config** (Object) - Sets custom configurations to workbox using `workbox.setConfig()`. For example, set `{ modulePathPrefix: '/third_party/workbox/' }` to use local workbox files instead of google CDN.

For list of all available options see [here](https://developers.google.com/web/tools/workbox/modules/workbox-build)

### Adding custom runtimeCaching items (For CDN)
Expand Down
2 changes: 2 additions & 0 deletions packages/workbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function getOptions (moduleOptions) {
directoryIndex: '/',
cachingExtensions: null,
routingExtensions: null,
config: null,
cacheId: process.env.npm_package_name || 'nuxt',
clientsClaim: true,
skipWaiting: true,
Expand Down Expand Up @@ -144,6 +145,7 @@ function addTemplates (options) {
offlineAssets: options.offlineAssets,
cachingExtensions: options.cachingExtensions,
routingExtensions: options.routingExtensions,
config: options.config,
importScripts: [options.wbDst].concat(options.importScripts || []),
runtimeCaching: [].concat(options._runtimeCaching, options.runtimeCaching).map(i => (Object.assign({}, i, {
urlPattern: i.urlPattern,
Expand Down
2 changes: 1 addition & 1 deletion packages/workbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"access": "public"
},
"dependencies": {
"workbox-build": "^3.4.1"
"workbox-build": "^3.5.0"
}
}
4 changes: 4 additions & 0 deletions packages/workbox/templates/sw.template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
importScripts(<%= options.importScripts.map((i) => `'${i}'`).join(', ') %>)

<% if (options.config) {%>
workbox.setConfig(<%= JSON.stringify(options.config, null, 2) %>)
<% } %>

workbox.precaching.precacheAndRoute([], <%= JSON.stringify(options.wbOptions, null, 2) %>)
<% if (options.offlineAssets.length) { %>
workbox.precaching.precacheAndRoute([<%= options.offlineAssets.map((i) => `'${i}'`).join(', ') %>])
Expand Down

0 comments on commit b5dab8a

Please sign in to comment.