diff --git a/packages/@vuepress/plugin-pwa/src/node/generateServiceWorker.ts b/packages/@vuepress/plugin-pwa/src/node/generateServiceWorker.ts index c58ca27795..9d682aaac2 100644 --- a/packages/@vuepress/plugin-pwa/src/node/generateServiceWorker.ts +++ b/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 @@ -21,15 +21,18 @@ const assetsExtensions = [ 'otf', ] +export type GenerateSWConfig = Omit< + GenerateSWOptions, + 'swDest' | 'globDirectory' +> + export const generateServiceWorker = async ( app: App, serviceWorkerFilename: string, - generateSWConfig: Partial[0]> + generateSWConfig: GenerateSWConfig ): Promise => { // 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) diff --git a/packages/@vuepress/plugin-pwa/src/node/pwaPlugin.ts b/packages/@vuepress/plugin-pwa/src/node/pwaPlugin.ts index 1246028706..1d3be42c7e 100644 --- a/packages/@vuepress/plugin-pwa/src/node/pwaPlugin.ts +++ b/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 { +export interface PwaPluginOptions extends GenerateSWConfig { /** * Filename of the generated service worker file *