11const { 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 ,
0 commit comments