Skip to content

Commit

Permalink
feat(workbox): improve sw.register
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Mar 17, 2019
1 parent cee50f5 commit c35f610
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/workbox/templates/sw.register.js
Original file line number Diff line number Diff line change
@@ -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.