Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workbox): workbox 3 + offlinePage #60

Merged
merged 51 commits into from Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
71fd73e
Update workbox version
manniL Apr 4, 2018
5d6da43
Migrate as far as possible
manniL Apr 4, 2018
ad667f6
fix: typos
manniL Jul 22, 2018
d7f76b1
chore: update workbox-build
manniL Jul 22, 2018
be984d7
chore: improve code layout
manniL Jul 22, 2018
fbe94c3
Merge branch 'master' into feature-update-workbox
galvez Aug 17, 2018
008c80e
Add scriptExtensions
galvez Aug 23, 2018
1500988
Add scriptExtensions (2)
galvez Aug 23, 2018
503b4e8
Fixed lint issue
galvez Aug 23, 2018
48a33fe
Split scriptExtensions into caching/routingExtensions
galvez Aug 23, 2018
b419b21
Sync latest master
galvez Aug 23, 2018
db2969a
Ongoing work on offlinePage support
galvez Aug 24, 2018
9e02827
Split scriptExtensions into caching/routingExtensions (2)
galvez Aug 24, 2018
17d2273
Split scriptExtensions into caching/routingExtensions (3)
galvez Aug 24, 2018
1c14733
Update eslint-standard
galvez Aug 24, 2018
bebad44
Contextualize eslint config
galvez Aug 24, 2018
45ab60a
Trying to fix upath error
galvez Aug 24, 2018
ad386a5
Update deps
galvez Aug 24, 2018
ad93e22
Update deps (2)
galvez Aug 24, 2018
81c7a51
Disable catch-all if offlinePage defined
galvez Aug 24, 2018
574e2de
Fix syntax error
galvez Aug 24, 2018
6e05406
Fix /.* route
galvez Aug 24, 2018
890d094
Clean up template
galvez Aug 24, 2018
a514b0d
Remove name from main package
galvez Aug 24, 2018
a036ea5
Fix placement of options
galvez Aug 24, 2018
96b8531
Remove npm bin
galvez Aug 24, 2018
3f4ab8b
reponse -> response
galvez Aug 24, 2018
092da26
Fix placement of cachingExtensions
galvez Aug 24, 2018
95600ca
Readd injection placeholder
galvez Aug 24, 2018
1f98a99
Move offlinePage to _runtimeCaching
galvez Aug 24, 2018
d93c6d4
Use lodash.pick()
galvez Aug 24, 2018
86a2f7f
Remove unused params
galvez Aug 24, 2018
ad5de91
Fix cacheId
galvez Aug 24, 2018
d1f29b0
Fix staleWhileRevalidate ref
galvez Aug 24, 2018
f3bf70e
Fix refs
galvez Aug 24, 2018
0e1b9a8
Debugging offlinePage
galvez Aug 24, 2018
d0cc8ac
Precache offlinePage
galvez Aug 24, 2018
b202189
Precache offlinePage (2)
galvez Aug 24, 2018
e3b1113
Offline page tweaks
galvez Aug 24, 2018
6a4dad5
Offline page tweaks (2)
galvez Aug 24, 2018
c673017
Offline page tweaks (3)
galvez Aug 24, 2018
cfb72d4
Offline page tweaks (4)
galvez Aug 24, 2018
f9c2e75
Offline page tweaks (5)
galvez Aug 24, 2018
3973c0e
Offline page tweaks (6)
galvez Aug 24, 2018
1d6d212
Offline page tweaks (7)
galvez Aug 24, 2018
4ba6913
Offline page tweaks (8)
galvez Aug 24, 2018
e6a7e78
Offline page tweaks (9)
galvez Aug 24, 2018
b8e2cf0
Offline page tweaks (10)
galvez Aug 24, 2018
469ff25
Offline page tweaks (11)
galvez Aug 24, 2018
b2bb50c
Update docs
galvez Aug 24, 2018
663651e
Add note to docs
galvez Aug 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/workbox/index.js
Expand Up @@ -98,10 +98,11 @@ function addTemplates (options) {
handler: i.handler || 'networkFirst',
method: i.method || 'GET'
}))),
clientClaims: options.clientClaims,
wbOptions: {
cacheId: options.cacheId,
clientsClaim: options.clientsClaim,
directoryIndex: options.directoryIndex
directoryIndex: options.directoryIndex,
cleanUrls: false
}
}
})
Expand Down Expand Up @@ -131,13 +132,13 @@ function emitAssets (options) {
const source = readFileSync(path)
const hash = hashSum(source)
const dst = `${name}.${hash}.${ext}`
assets.push({source, dst})
assets.push({ source, dst })
return dst
}

// Write assets after build
const hook = builder => {
assets.forEach(({source, dst}) => {
assets.forEach(({ source, dst }) => {
writeFileSync(path.resolve(this.options.buildDir, 'dist', dst), source, 'utf-8')
})
}
Expand Down Expand Up @@ -165,6 +166,11 @@ function emitAssets (options) {
function workboxInject (options) {
const hook = () => {
const opts = Object.assign({}, options)
const VALID_KEYS = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also use lodash _.pick

'swDest', 'swSrc', 'globDirectory', 'globFollow', 'globIgnores', 'globPatterns', 'dontCacheBustUrlsMatching',
'globStrict', 'templatedUrls', 'maximumFileSizeToCacheInBytes', 'modifyUrlPrefix', 'manifestTransforms'
]
Object.keys(opts).filter(k => !VALID_KEYS.includes(k)).forEach(k => { delete opts[k] })
delete opts.runtimeCaching
return swBuild.injectManifest(opts)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/workbox/package.json
Expand Up @@ -8,6 +8,6 @@
"access": "public"
},
"dependencies": {
"workbox-build": "^2.1.2"
"workbox-build": "^3.0.1"
}
}
9 changes: 6 additions & 3 deletions packages/workbox/templates/sw.template.js
@@ -1,11 +1,14 @@
importScripts(<%= options.importScripts.map(i => `'${i}'`).join(', ') %>)

const workboxSW = new self.WorkboxSW(<%= JSON.stringify(options.wbOptions, null, 2) %>)
workbox.precaching.precacheAndRoute([], <%= JSON.stringify(options.wbOptions, null, 2) %>)

workboxSW.precache([])

<% if(options.clientClaims) { %>
workbox.clientClaims()
<% } %>

<% options.runtimeCaching.forEach(r => {
const strategy = JSON.stringify(r.strategyOptions || {})
%>
workboxSW.router.registerRoute(new RegExp('<%= r.urlPattern %>'), workboxSW.strategies.<%= r.handler %>(<%= strategy %>), '<%= r.method %>')
workbox.routing.registerRoute(new RegExp('<%= r.urlPattern %>'), workboxSW.strategies.<%= r.handler %>(<%= strategy %>), '<%= r.method %>')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should workboxSW.strategies be workbox.strategies?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will fix!

<% }) %>