Skip to content

Commit

Permalink
fix(api): return pwa info when required (#378)
Browse files Browse the repository at this point in the history
* fix(api): webmanifest should be generated always

* chore: check also manifest is present

* chore: update to logic to only return when required
  • Loading branch information
userquin committed Sep 22, 2022
1 parent f8aba11 commit 4927b19
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/api.ts
Expand Up @@ -63,7 +63,7 @@ export function createAPI(ctx: PWAPluginContext): VitePluginPWAAPI {
},
webManifestData() {
const options = ctx?.options
if (!options || options.disable || ctx.viteConfig.build.ssr || (ctx.devEnvironment && !ctx.options.devOptions.enabled))
if (!options || options.disable || !options.manifest || (ctx.devEnvironment && !ctx.options.devOptions.enabled))
return undefined

let url = options.manifestFilename
Expand All @@ -85,14 +85,18 @@ export function createAPI(ctx: PWAPluginContext): VitePluginPWAAPI {
}
},
registerSWData() {
// we'll return the info only when it is required
// 1: exclude if not enabled
const options = ctx?.options
if (!options || options.disable || ctx.viteConfig.build.ssr || (ctx.devEnvironment && !ctx.options.devOptions.enabled))
if (!options || options.disable || (ctx.devEnvironment && !ctx.options.devOptions.enabled))
return undefined

// 2: if manual registration or using virtual
const mode = options.injectRegister
if (!mode || ctx.useImportRegister)
return undefined

// 3: otherwise we always return the info
let type: WorkerType = 'classic'
let script: string | undefined
let shouldRegisterSW = options.injectRegister === 'inline' || options.injectRegister === 'script'
Expand All @@ -106,6 +110,7 @@ export function createAPI(ctx: PWAPluginContext): VitePluginPWAAPI {
}

return {
// hint when required
shouldRegisterSW,
inline: options.injectRegister === 'inline',
scope: options.scope,
Expand Down

0 comments on commit 4927b19

Please sign in to comment.