File tree Expand file tree Collapse file tree 1 file changed +16
-11
lines changed
packages/workbox/templates Expand file tree Collapse file tree 1 file changed +16
-11
lines changed Original file line number Diff line number Diff line change 1- import { Workbox } from 'workbox-cdn/workbox/workbox-window.<%= options.dev ? ' dev ' : 'prod ' % > . es5 . mjs '
1+ export default async function ( ctx , inject ) {
2+ let workbox = { }
23
3- export default async function ( ctx , inject ) {
4- const workbox = new Workbox ( '<%= options.swURL %>' , {
5- scope : '<%= options.swScope %>'
6- } )
4+ try {
5+ if ( ! 'serviceWorker' in navigator ) {
6+ throw new Error ( 'Serviceworker is not supported!' )
7+ }
78
8- // Inject as $workbox
9- inject ( 'workbox' , workbox )
9+ const { Workbox } = require ( 'workbox-cdn/workbox/workbox-window.<%= options.dev ? ' dev ' : 'prod' % > . es5 . mjs ')
10+
11+ workbox = new Workbox ( '<%= options.swURL %>' , {
12+ scope : '<%= options.swScope %>'
13+ } )
1014
11- if ( ! 'serviceWorker' in navigator ) {
12- workbox . _unsupported = true
13- return // Unsupported browser!
15+ workbox . register ( )
16+ } catch ( e ) {
17+ console . warn ( 'Cannot register workbox:' , e )
1418 }
1519
16- workbox . register ( )
20+ // Inject as $workbox
21+ inject ( 'workbox' , workbox )
1722}
You can’t perform that action at this time.
0 commit comments