Skip to content

Commit d42184a

Browse files
authored
fix(dev): custom service worker with custom base not working (#688)
1 parent e195fe2 commit d42184a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/plugins/dev.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ export function DevPlugin(ctx: PWAPluginContext) {
9393

9494
const { options } = ctx
9595
if (!options.disable && options.devOptions.enabled && options.strategies === 'injectManifest' && !options.selfDestroying) {
96-
const name = id.startsWith(options.base) ? id.slice(options.base.length) : id
96+
let name = id.startsWith(options.base) ? id.slice(options.base.length) : id
97+
// Vite will remove the base from the request, and so we need to remove the leading /: fixes issue #683
98+
if (name.length && name[0] === '/')
99+
name = name.slice(1)
97100
// the sw must be registered with .js extension in the browser, here we detect that request:
98101
// - the .js file and source with .ts, or
99102
// - the .ts source file

0 commit comments

Comments
 (0)