From 76ecf22f24bc4a07a14ac62b92611a91cf2ea2eb Mon Sep 17 00:00:00 2001 From: Kevin Marrec Date: Tue, 11 Oct 2022 15:00:59 +0200 Subject: [PATCH] feat: add workbox.autoRegister option Resolves #46 --- codecov.yaml | 1 + src/module.ts | 1 + src/parts/workbox/index.ts | 13 ++++++++----- src/parts/workbox/types.ts | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 codecov.yaml diff --git a/codecov.yaml b/codecov.yaml new file mode 100644 index 0000000..f105d5a --- /dev/null +++ b/codecov.yaml @@ -0,0 +1 @@ +github_checks: false diff --git a/src/module.ts b/src/module.ts index b804bdf..503ef06 100644 --- a/src/module.ts +++ b/src/module.ts @@ -53,6 +53,7 @@ export default defineNuxtModule({ twitterCreator: undefined, }, workbox: { + autoRegister: true, enabled: !nuxt.options.dev, templatePath: null, workboxVersion: '6.5.3', diff --git a/src/parts/workbox/index.ts b/src/parts/workbox/index.ts index 12e782c..efc207b 100644 --- a/src/parts/workbox/index.ts +++ b/src/parts/workbox/index.ts @@ -18,7 +18,7 @@ export default async (pwa: PWAContext) => { if (!options.workboxUrl) options.workboxUrl = `https://storage.googleapis.com/workbox-cdn/releases/${options.workboxVersion}/workbox-sw.js` - // Service Worker + // Define Service Worker addTemplate({ src: options.templatePath ? await pwa._resolver.resolvePath(options.templatePath) : pwa._resolver.resolve('../templates/workbox/sw.js'), dst: join(pwa._buildDir, 'sw.js'), @@ -26,8 +26,11 @@ export default async (pwa: PWAContext) => { options, }) - nuxt.hook('nitro:config', (config) => { - config.plugins = config.plugins || [] - config.plugins.push(pwa._resolver.resolve('./runtime/nitro-plugin')) - }) + // Register Service Worker + if (options.autoRegister) { + nuxt.hook('nitro:config', (config) => { + config.plugins = config.plugins || [] + config.plugins.push(pwa._resolver.resolve('./runtime/nitro-plugin')) + }) + } } diff --git a/src/parts/workbox/types.ts b/src/parts/workbox/types.ts index 2be9057..71adf60 100644 --- a/src/parts/workbox/types.ts +++ b/src/parts/workbox/types.ts @@ -1,4 +1,5 @@ export interface WorkboxOptions { + autoRegister: boolean enabled: boolean templatePath: string | null workboxVersion: string