From d42184a8f1eefce9b3b0796358a70cb984a9b1d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Tue, 19 Mar 2024 12:32:01 +0100 Subject: [PATCH] fix(dev): custom service worker with custom base not working (#688) --- src/plugins/dev.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugins/dev.ts b/src/plugins/dev.ts index 59803db9..fc427d0e 100644 --- a/src/plugins/dev.ts +++ b/src/plugins/dev.ts @@ -93,7 +93,10 @@ export function DevPlugin(ctx: PWAPluginContext) { const { options } = ctx if (!options.disable && options.devOptions.enabled && options.strategies === 'injectManifest' && !options.selfDestroying) { - const name = id.startsWith(options.base) ? id.slice(options.base.length) : id + let name = id.startsWith(options.base) ? id.slice(options.base.length) : id + // Vite will remove the base from the request, and so we need to remove the leading /: fixes issue #683 + if (name.length && name[0] === '/') + name = name.slice(1) // the sw must be registered with .js extension in the browser, here we detect that request: // - the .js file and source with .ts, or // - the .ts source file