Skip to content

Commit 713157a

Browse files
authored
Ensure vite.config.js works on Windows (#5265)
* Ensure vite.config.js works on Windows * format * try to fix windows * changeset
1 parent fb295fe commit 713157a

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

.changeset/neat-monkeys-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[fix] support vite.config.js on Windows

packages/kit/src/cli.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import path from 'path';
44
import colors from 'kleur';
55
import sade from 'sade';
66
import * as vite from 'vite';
7-
import { load_config } from './core/config/index.js';
87
import { networkInterfaces, release } from 'os';
8+
import { pathToFileURL } from 'url';
9+
import { load_config } from './core/config/index.js';
910
import { coalesce_to_error } from './utils/error.js';
1011

1112
/** @param {unknown} e */
@@ -289,7 +290,7 @@ export async function get_vite_config(svelte_config) {
289290
for (const file of ['vite.config.js', 'vite.config.mjs', 'vite.config.cjs']) {
290291
if (fs.existsSync(file)) {
291292
// TODO warn here if config.kit.vite was specified
292-
const module = await import(path.resolve(file));
293+
const module = await import(pathToFileURL(file).toString());
293294
return {
294295
...module.default,
295296
configFile: false

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as path from 'path';
2-
31
/** @type {import('@sveltejs/kit').Config} */
42
const config = {
53
kit: {
@@ -8,16 +6,6 @@ const config = {
86
},
97
serviceWorker: {
108
register: false
11-
},
12-
vite: {
13-
server: {
14-
// TODO: required to support ipv6, remove on vite 3
15-
// https://github.com/vitejs/vite/issues/7075
16-
host: 'localhost',
17-
fs: {
18-
allow: [path.resolve('../../../src')]
19-
}
20-
}
219
}
2210
}
2311
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as path from 'path';
2+
import { sveltekit } from '@sveltejs/kit/experimental/vite';
3+
4+
/** @type {import('vite').UserConfig} */
5+
const config = {
6+
plugins: [sveltekit()],
7+
server: {
8+
// TODO: required to support ipv6, remove on vite 3
9+
// https://github.com/vitejs/vite/issues/7075
10+
host: 'localhost',
11+
fs: {
12+
allow: [path.resolve('../../../src')]
13+
}
14+
}
15+
};
16+
17+
export default config;

0 commit comments

Comments
 (0)