Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] set Vite base URL #8046

Merged
merged 4 commits into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/index.js
Expand Up @@ -253,7 +253,7 @@ function kit({ svelte_config }) {
/** @type {import('vite').UserConfig} */
const result = {
appType: 'custom',
base: './',
base: svelte_config.kit.paths.base,
build: {
rollupOptions: {
// Vite dependency crawler needs an explicit JS entry point
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/apps/options/source/template.html
Expand Up @@ -9,6 +9,6 @@
<body>
<h1>I am in the template</h1>
<div>%sveltekit.body%</div>
<a href="/path-base/routing/link-outside-app-target/target">outside app target</a>
<a href="/path-base/routing/link-outside-app-target/target/">outside app target</a>
</body>
</html>
16 changes: 11 additions & 5 deletions packages/kit/test/apps/options/test/test.js
Expand Up @@ -9,9 +9,15 @@ test.describe('base path', () => {
test('serves a useful 404 when visiting unprefixed path', async ({ request }) => {
const html = await request.get('/slash/', { headers: { Accept: 'text/html' } });
expect(html.status()).toBe(404);
expect(await html.text()).toBe(
'Not found (did you mean <a href="/path-base/slash/">/path-base/slash/</a>?)'
);
if (process.env.DEV) {
// Vite's message
expect(await html.text()).toBe(
'The server is configured with a public base URL of /path-base - did you mean to visit <a href=\"/path-base/slash/\">/path-base/slash/</a> instead?'
);
} else {
// SvelteKit's message
expect(await html.text()).toBe('Not found (did you mean <a href=\"/path-base/slash/\">/path-base/slash/</a>?)');
benmccann marked this conversation as resolved.
Show resolved Hide resolved
}

const plain = await request.get('/slash/');
expect(plain.status()).toBe(404);
Expand Down Expand Up @@ -248,9 +254,9 @@ test.describe('Vite options', () => {

test.describe('Routing', () => {
test('ignores clicks outside the app target', async ({ page }) => {
await page.goto('/path-base/routing/link-outside-app-target/source');
await page.goto('/path-base/routing/link-outside-app-target/source/');

await page.click('[href="/path-base/routing/link-outside-app-target/target"]');
await page.click('[href="/path-base/routing/link-outside-app-target/target/"]');
await expect(page.locator('h2')).toHaveText('target: 0');
});
});