-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pooya parsa
committed
Mar 17, 2019
1 parent
cee50f5
commit c35f610
Showing
1 changed file
with
16 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |