Skip to content

Commit 604052b

Browse files
authored
fix($plugin-pwa): work with register-service-worker 1.7.0 (close #2222) (#2229)
1 parent f7a78b4 commit 604052b

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

packages/@vuepress/plugin-pwa/lib/enhanceAppFile.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* global SW_BASE_URL, SW_ENABLED, GA_ID, ga, SW_UPDATE_POPUP, SW_POPUP_COMPONENT */
22

33
import Vue from 'vue'
4-
import { register } from 'register-service-worker'
54
import SWUpdateEvent from './SWUpdateEvent'
65
import event from './event'
76

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

13-
export default ({ router, isServer }) => {
14-
// Register service worker
15-
router.onReady(() => {
16-
if (process.env.NODE_ENV === 'production'
17-
&& !isServer
18-
&& SW_ENABLED) {
12+
export default async ({ router, isServer }) => {
13+
if (process.env.NODE_ENV === 'production' && !isServer && SW_ENABLED) {
14+
// [email protected] references `window` in outer scope, so we have to import it dynamically in client
15+
const { register } = await import('register-service-worker')
16+
17+
// Register service worker
18+
router.onReady(() => {
1919
register(`${SW_BASE_URL}service-worker.js`, {
2020
registrationOptions: {},
2121
ready () {
@@ -49,6 +49,6 @@ export default ({ router, isServer }) => {
4949
}
5050
}
5151
})
52-
}
53-
})
52+
})
53+
}
5454
}

packages/@vuepress/plugin-pwa/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"main": "index.js",
2323
"dependencies": {
2424
"@vuepress/shared-utils": "^1.3.1",
25-
"register-service-worker": "^1.5.2",
25+
"register-service-worker": "^1.7.0",
2626
"workbox-build": "^4.3.1"
2727
},
2828
"publishConfig": {

yarn.lock

+4-3
Original file line numberDiff line numberDiff line change
@@ -11104,9 +11104,10 @@ regexpu-core@^4.6.0:
1110411104
unicode-match-property-ecmascript "^1.0.4"
1110511105
unicode-match-property-value-ecmascript "^1.1.0"
1110611106

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

1111111112
registry-auth-token@^4.0.0:
1111211113
version "4.0.0"

0 commit comments

Comments
 (0)