Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
feat: add workbox.autoRegister option
Browse files Browse the repository at this point in the history
Resolves #46
  • Loading branch information
kevinmarrec committed Oct 11, 2022
1 parent 79063ef commit 76ecf22
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github_checks: false
1 change: 1 addition & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default defineNuxtModule<PWAOptions>({
twitterCreator: undefined,
},
workbox: {
autoRegister: true,
enabled: !nuxt.options.dev,
templatePath: null,
workboxVersion: '6.5.3',
Expand Down
13 changes: 8 additions & 5 deletions src/parts/workbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ 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'),
write: true,
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'))
})
}
}
1 change: 1 addition & 0 deletions src/parts/workbox/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface WorkboxOptions {
autoRegister: boolean
enabled: boolean
templatePath: string | null
workboxVersion: string
Expand Down

0 comments on commit 76ecf22

Please sign in to comment.