1
1
const { logger, fs, path } = require ( '@vuepress/shared-utils' )
2
2
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 ) => ( {
11
9
alias : {
12
10
'@sw-event' : path . resolve ( __dirname , 'lib/event.js' )
13
11
} ,
14
12
15
13
define ( ) {
16
- const { serviceWorker, updatePopup } = options
17
14
const base = context . base || '/'
18
15
return {
19
16
SW_BASE_URL : base ,
20
17
SW_ENABLED : ! ! serviceWorker ,
21
- SW_UPDATE_POPUP : updatePopup || false
18
+ SW_UPDATE_POPUP : updatePopup ,
19
+ SW_POPUP_COMPONENT : popupComponent
22
20
}
23
21
} ,
24
22
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 ,
31
24
32
25
enhanceAppFiles : path . resolve ( __dirname , 'lib/enhanceAppFile.js' ) ,
33
26
34
27
async generated ( ) {
35
- const { serviceWorker } = options
36
28
const { outDir } = context
37
29
const swFilePath = path . resolve ( outDir , 'service-worker.js' )
38
30
if ( serviceWorker ) {
@@ -42,7 +34,7 @@ module.exports = (options, context) => ({
42
34
swDest : swFilePath ,
43
35
globDirectory : outDir ,
44
36
globPatterns : [ '**\/*.{js,css,html,png,jpg,jpeg,gif,svg,woff,woff2,eot,ttf,otf}' ] ,
45
- ...( options . generateSWConfig || { } )
37
+ ...generateSWConfig
46
38
} )
47
39
await fs . writeFile (
48
40
swFilePath ,
0 commit comments