Skip to content

Commit

Permalink
fix($plugin-pwa): work with register-service-worker 1.7.0 (close #2222)…
Browse files Browse the repository at this point in the history
… (#2229)
  • Loading branch information
meteorlxy authored Mar 18, 2020
1 parent f7a78b4 commit 604052b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
18 changes: 9 additions & 9 deletions packages/@vuepress/plugin-pwa/lib/enhanceAppFile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global SW_BASE_URL, SW_ENABLED, GA_ID, ga, SW_UPDATE_POPUP, SW_POPUP_COMPONENT */

import Vue from 'vue'
import { register } from 'register-service-worker'
import SWUpdateEvent from './SWUpdateEvent'
import event from './event'

Expand All @@ -10,12 +9,13 @@ if (SW_UPDATE_POPUP && SW_POPUP_COMPONENT === 'SWUpdatePopup') {
Vue.component('SWUpdatePopup', () => import('./SWUpdatePopup.vue'))
}

export default ({ router, isServer }) => {
// Register service worker
router.onReady(() => {
if (process.env.NODE_ENV === 'production'
&& !isServer
&& SW_ENABLED) {
export default async ({ router, isServer }) => {
if (process.env.NODE_ENV === 'production' && !isServer && SW_ENABLED) {
// [email protected] references `window` in outer scope, so we have to import it dynamically in client
const { register } = await import('register-service-worker')

// Register service worker
router.onReady(() => {
register(`${SW_BASE_URL}service-worker.js`, {
registrationOptions: {},
ready () {
Expand Down Expand Up @@ -49,6 +49,6 @@ export default ({ router, isServer }) => {
}
}
})
}
})
})
}
}
2 changes: 1 addition & 1 deletion packages/@vuepress/plugin-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"main": "index.js",
"dependencies": {
"@vuepress/shared-utils": "^1.3.1",
"register-service-worker": "^1.5.2",
"register-service-worker": "^1.7.0",
"workbox-build": "^4.3.1"
},
"publishConfig": {
Expand Down
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11104,9 +11104,10 @@ regexpu-core@^4.6.0:
unicode-match-property-ecmascript "^1.0.4"
unicode-match-property-value-ecmascript "^1.1.0"

register-service-worker@^1.5.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/register-service-worker/-/register-service-worker-1.6.2.tgz#9297e54c205c371c6e49bfa88f6997e8dd315f4c"
register-service-worker@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/register-service-worker/-/register-service-worker-1.7.0.tgz#b4b60d87a1d117f119bfd24ece073dcdb85dae64"
integrity sha512-sJQIxgodrulyN4d+bTkRnroPNMH3i1J4kP7Wm+vLhTP5CdbDSRr5jCeC9sJ6jyL603IZVbMAZ5HcU0hWCbJQQA==

registry-auth-token@^4.0.0:
version "4.0.0"
Expand Down

0 comments on commit 604052b

Please sign in to comment.