Skip to content

Commit

Permalink
fix: service worker base path in dev mode (#12577)
Browse files Browse the repository at this point in the history
Fixes #12039
  • Loading branch information
TorstenDittmann authored Jan 15, 2025
1 parent e2a4538 commit 9dc5c0e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-geese-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: service worker base path in dev mode
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export async function dev(vite, vite_config, svelte_config) {
res.writeHead(200, {
'content-type': 'application/javascript'
});
res.end(`import '${to_fs(resolved)}';`);
res.end(`import '${svelte_config.kit.paths.base}${to_fs(resolved)}';`);
} else {
res.writeHead(404);
res.end('not found');
Expand Down
15 changes: 14 additions & 1 deletion packages/kit/test/apps/options-2/test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { expect } from '@playwright/test';
import { test } from '../../../utils.js';

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

test.describe('Service worker', () => {
if (process.env.DEV) return;
if (process.env.DEV) {
test('import proxy /basepath/service-worker.js', async ({ request }) => {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const response = await request.get('/basepath/service-worker.js');
const content = await response.text();
expect(content).toEqual(
`import '${path.join('/basepath', '/@fs', __dirname, '../src/service-worker.js')}';`
);
});

return;
}

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

0 comments on commit 9dc5c0e

Please sign in to comment.