Skip to content

Commit

Permalink
feat(plugin-pwa): improve types definition
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Jun 5, 2022
1 parent 07fbe43 commit e7590f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
13 changes: 8 additions & 5 deletions packages/@vuepress/plugin-pwa/src/node/generateServiceWorker.ts
@@ -1,6 +1,6 @@
import type { App } from '@vuepress/core'
import { logger } from '@vuepress/utils'
import type { generateSW as GenerateSWFunc } from 'workbox-build'
import type { GenerateSWOptions } from 'workbox-build'

const assetsExtensions = [
// basic
Expand All @@ -21,15 +21,18 @@ const assetsExtensions = [
'otf',
]

export type GenerateSWConfig = Omit<
GenerateSWOptions,
'swDest' | 'globDirectory'
>

export const generateServiceWorker = async (
app: App,
serviceWorkerFilename: string,
generateSWConfig: Partial<Parameters<typeof GenerateSWFunc>[0]>
generateSWConfig: GenerateSWConfig
): Promise<void> => {
// lazy-load workbox-build
const { generateSW } = require('workbox-build') as {
generateSW: typeof GenerateSWFunc
}
const { generateSW } = await import('workbox-build')

const globDirectory = app.dir.dest()
const swDest = app.dir.dest(serviceWorkerFilename)
Expand Down
5 changes: 2 additions & 3 deletions packages/@vuepress/plugin-pwa/src/node/pwaPlugin.ts
@@ -1,13 +1,12 @@
import type { Plugin, PluginObject } from '@vuepress/core'
import { path, withSpinner } from '@vuepress/utils'
import { generateServiceWorker } from './generateServiceWorker'
import type { GenerateSWConfig } from './generateServiceWorker'

/**
* Options for @vuepress/plugin-pwa
*/
export interface PwaPluginOptions
// TODO: the type of the parameter of generateSW is missing
extends Omit<any, 'swDest' | 'globDirectory'> {
export interface PwaPluginOptions extends GenerateSWConfig {
/**
* Filename of the generated service worker file
*
Expand Down

0 comments on commit e7590f4

Please sign in to comment.