Skip to content

Commit

Permalink
chore: if registerSW exists justa add it to the dev map
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Sep 6, 2022
1 parent 9de6d17 commit 8a78d23
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/plugins/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,13 @@ async function createDevRegisterSW(options: ResolvedVitePWAOptions, viteConfig:
mkdirSync(devDist)

const registerSW = resolve(devDist, FILE_SW_REGISTER)
if (existsSync(registerSW))
if (existsSync(registerSW)) {
// since we don't delete the dev-dist folder, we just add it if already exists
if (!swDevOptions.workboxPaths.has(registerSW))
swDevOptions.workboxPaths.set(normalizePath(`${options.base}${FILE_SW_REGISTER}`), registerSW)

return
}

await fs.writeFile(registerSW, generateSimpleSWRegister(options, true), { encoding: 'utf8' })
swDevOptions.workboxPaths.set(normalizePath(`${options.base}${FILE_SW_REGISTER}`), registerSW)
Expand Down

0 comments on commit 8a78d23

Please sign in to comment.