-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(workbox): workbox-window support
- Loading branch information
pooya parsa
committed
Mar 5, 2019
1 parent
4e9aee5
commit 2e356d0
Showing
4 changed files
with
34 additions
and
7 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
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
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,9 +1,17 @@ | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.register('<%= options.swURL %>', { | ||
import { Workbox } from 'workbox-window/build/workbox-window.<%= options.dev ? 'dev' : 'prod' %>.mjs' | ||
export default async function(ctx, inject) { | ||
const workbox = new Workbox('<%= options.swURL %>', { | ||
scope: '<%= options.swScope %>' | ||
}).then(function(registration) { | ||
window.$sw = registration | ||
}).catch(function(error) { | ||
console.error('Service worker registration failed:', error) | ||
}) | ||
// Inject as $workbox | ||
inject('workbox', workbox) | ||
if (!'serviceWorker' in navigator) { | ||
workbox._unsupported = true | ||
return // Unsupported browser! | ||
} | ||
|
||
workbox.register() | ||
} |
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