Skip to content
Permalink
Browse files
feat(workbox): improve sw.register
  • Loading branch information
pooya parsa committed Mar 17, 2019
1 parent cee50f5 commit c35f6104a66ef125a0d33f8e32ee8f5f9a1cfc28
Showing 1 changed file with 16 additions and 11 deletions.
@@ -1,17 +1,22 @@
import { Workbox } from 'workbox-cdn/workbox/workbox-window.<%= options.dev ? 'dev' : 'prod' %>.es5.mjs'
export default async function (ctx, inject) {
let workbox = {}

export default async function(ctx, inject) {
const workbox = new Workbox('<%= options.swURL %>', {
scope: '<%= options.swScope %>'
})
try {
if (!'serviceWorker' in navigator) {
throw new Error('Serviceworker is not supported!')
}

// Inject as $workbox
inject('workbox', workbox)
const { Workbox } = require('workbox-cdn/workbox/workbox-window.<%= options.dev ? 'dev' : 'prod' %>.es5.mjs')
workbox = new Workbox('<%= options.swURL %>', {
scope: '<%= options.swScope %>'
})
if (!'serviceWorker' in navigator) {
workbox._unsupported = true
return // Unsupported browser!
workbox.register()
} catch (e) {
console.warn('Cannot register workbox:', e)
}
workbox.register()
// Inject as $workbox
inject('workbox', workbox)
}

0 comments on commit c35f610

Please sign in to comment.