Skip to content

Commit b5dab8a

Browse files
CarterLipi0
authored andcommittedSep 21, 2018
feat(workbox): support pass config object to workbox.setConfig (#95)
1 parent 575f713 commit b5dab8a

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed
 

Diff for: ‎docs/modules/workbox.md

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ workbox: {
3333

3434
**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.
3535

36+
**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.
37+
3638
For list of all available options see [here](https://developers.google.com/web/tools/workbox/modules/workbox-build)
3739

3840
### Adding custom runtimeCaching items (For CDN)

Diff for: ‎packages/workbox/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ function getOptions (moduleOptions) {
8080
directoryIndex: '/',
8181
cachingExtensions: null,
8282
routingExtensions: null,
83+
config: null,
8384
cacheId: process.env.npm_package_name || 'nuxt',
8485
clientsClaim: true,
8586
skipWaiting: true,
@@ -144,6 +145,7 @@ function addTemplates (options) {
144145
offlineAssets: options.offlineAssets,
145146
cachingExtensions: options.cachingExtensions,
146147
routingExtensions: options.routingExtensions,
148+
config: options.config,
147149
importScripts: [options.wbDst].concat(options.importScripts || []),
148150
runtimeCaching: [].concat(options._runtimeCaching, options.runtimeCaching).map(i => (Object.assign({}, i, {
149151
urlPattern: i.urlPattern,

Diff for: ‎packages/workbox/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"access": "public"
99
},
1010
"dependencies": {
11-
"workbox-build": "^3.4.1"
11+
"workbox-build": "^3.5.0"
1212
}
1313
}

Diff for: ‎packages/workbox/templates/sw.template.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
importScripts(<%= options.importScripts.map((i) => `'${i}'`).join(', ') %>)
22

3+
<% if (options.config) {%>
4+
workbox.setConfig(<%= JSON.stringify(options.config, null, 2) %>)
5+
<% } %>
6+
37
workbox.precaching.precacheAndRoute([], <%= JSON.stringify(options.wbOptions, null, 2) %>)
48
<% if (options.offlineAssets.length) { %>
59
workbox.precaching.precacheAndRoute([<%= options.offlineAssets.map((i) => `'${i}'`).join(', ') %>])

0 commit comments

Comments
 (0)
Please sign in to comment.