Skip to content

Commit 9dc5c0e

Browse files
fix: service worker base path in dev mode (#12577)
Fixes #12039
1 parent e2a4538 commit 9dc5c0e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.changeset/nice-geese-serve.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: service worker base path in dev mode

packages/kit/src/exports/vite/dev/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export async function dev(vite, vite_config, svelte_config) {
462462
res.writeHead(200, {
463463
'content-type': 'application/javascript'
464464
});
465-
res.end(`import '${to_fs(resolved)}';`);
465+
res.end(`import '${svelte_config.kit.paths.base}${to_fs(resolved)}';`);
466466
} else {
467467
res.writeHead(404);
468468
res.end('not found');

packages/kit/test/apps/options-2/test/test.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import path from 'node:path';
12
import process from 'node:process';
3+
import { fileURLToPath } from 'node:url';
24
import { expect } from '@playwright/test';
35
import { test } from '../../../utils.js';
46

@@ -73,7 +75,18 @@ test.describe('trailing slash', () => {
7375
});
7476

7577
test.describe('Service worker', () => {
76-
if (process.env.DEV) return;
78+
if (process.env.DEV) {
79+
test('import proxy /basepath/service-worker.js', async ({ request }) => {
80+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
81+
const response = await request.get('/basepath/service-worker.js');
82+
const content = await response.text();
83+
expect(content).toEqual(
84+
`import '${path.join('/basepath', '/@fs', __dirname, '../src/service-worker.js')}';`
85+
);
86+
});
87+
88+
return;
89+
}
7790

7891
test('build /basepath/service-worker.js', async ({ baseURL, request }) => {
7992
const response = await request.get('/basepath/service-worker.js');

0 commit comments

Comments
 (0)