Skip to content

Commit 560b3c6

Browse files
authored
fix($plugin-pwa): popup component does not work (close #2172) (#2187)
1 parent 606ae4a commit 560b3c6

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

packages/@vuepress/plugin-pwa/index.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
const { logger, fs, path } = require('@vuepress/shared-utils')
22

3-
module.exports = (options, context) => ({
4-
ready () {
5-
options = Object.assign({
6-
serviceWorker: true,
7-
popupComponent: 'SWUpdatePopup'
8-
}, options)
9-
},
10-
3+
module.exports = ({
4+
serviceWorker = true,
5+
updatePopup = false,
6+
popupComponent = 'SWUpdatePopup',
7+
generateSWConfig = {}
8+
}, context) => ({
119
alias: {
1210
'@sw-event': path.resolve(__dirname, 'lib/event.js')
1311
},
1412

1513
define () {
16-
const { serviceWorker, updatePopup } = options
1714
const base = context.base || '/'
1815
return {
1916
SW_BASE_URL: base,
2017
SW_ENABLED: !!serviceWorker,
21-
SW_UPDATE_POPUP: updatePopup || false
18+
SW_UPDATE_POPUP: updatePopup,
19+
SW_POPUP_COMPONENT: popupComponent
2220
}
2321
},
2422

25-
// TODO support components option
26-
// components: [
27-
// { name: 'SWUpdatePopup', path: path.resolve(__dirname, 'lib/SWUpdatePopup.vue') }
28-
// ],
29-
30-
globalUIComponents: options.updatePopup ? options.popupComponent : undefined,
23+
globalUIComponents: updatePopup ? popupComponent : undefined,
3124

3225
enhanceAppFiles: path.resolve(__dirname, 'lib/enhanceAppFile.js'),
3326

3427
async generated () {
35-
const { serviceWorker } = options
3628
const { outDir } = context
3729
const swFilePath = path.resolve(outDir, 'service-worker.js')
3830
if (serviceWorker) {
@@ -42,7 +34,7 @@ module.exports = (options, context) => ({
4234
swDest: swFilePath,
4335
globDirectory: outDir,
4436
globPatterns: ['**\/*.{js,css,html,png,jpg,jpeg,gif,svg,woff,woff2,eot,ttf,otf}'],
45-
...(options.generateSWConfig || {})
37+
...generateSWConfig
4638
})
4739
await fs.writeFile(
4840
swFilePath,

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

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

33
import Vue from 'vue'
44
import { register } from 'register-service-worker'
55
import SWUpdateEvent from './SWUpdateEvent'
66
import event from './event'
77

8-
if (SW_UPDATE_POPUP) {
8+
if (SW_UPDATE_POPUP && SW_POPUP_COMPONENT === 'SWUpdatePopup') {
99
// eslint-disable-next-line vue/match-component-file-name
1010
Vue.component('SWUpdatePopup', () => import('./SWUpdatePopup.vue'))
1111
}

0 commit comments

Comments
 (0)