diff --git a/.changeset/neat-monkeys-dream.md b/.changeset/neat-monkeys-dream.md new file mode 100644 index 000000000000..4c6ee0d0afae --- /dev/null +++ b/.changeset/neat-monkeys-dream.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[fix] support vite.config.js on Windows diff --git a/packages/kit/src/cli.js b/packages/kit/src/cli.js index 1dcff209afd4..d08ac2f3e046 100755 --- a/packages/kit/src/cli.js +++ b/packages/kit/src/cli.js @@ -4,8 +4,9 @@ import path from 'path'; import colors from 'kleur'; import sade from 'sade'; import * as vite from 'vite'; -import { load_config } from './core/config/index.js'; import { networkInterfaces, release } from 'os'; +import { pathToFileURL } from 'url'; +import { load_config } from './core/config/index.js'; import { coalesce_to_error } from './utils/error.js'; /** @param {unknown} e */ @@ -289,7 +290,7 @@ export async function get_vite_config(svelte_config) { for (const file of ['vite.config.js', 'vite.config.mjs', 'vite.config.cjs']) { if (fs.existsSync(file)) { // TODO warn here if config.kit.vite was specified - const module = await import(path.resolve(file)); + const module = await import(pathToFileURL(file).toString()); return { ...module.default, configFile: false diff --git a/packages/kit/test/apps/options-2/svelte.config.js b/packages/kit/test/apps/options-2/svelte.config.js index 5d46d5f640fd..29ef3a0e1285 100644 --- a/packages/kit/test/apps/options-2/svelte.config.js +++ b/packages/kit/test/apps/options-2/svelte.config.js @@ -1,5 +1,3 @@ -import * as path from 'path'; - /** @type {import('@sveltejs/kit').Config} */ const config = { kit: { @@ -8,16 +6,6 @@ const config = { }, serviceWorker: { register: false - }, - vite: { - server: { - // TODO: required to support ipv6, remove on vite 3 - // https://github.com/vitejs/vite/issues/7075 - host: 'localhost', - fs: { - allow: [path.resolve('../../../src')] - } - } } } }; diff --git a/packages/kit/test/apps/options-2/vite.config.js b/packages/kit/test/apps/options-2/vite.config.js new file mode 100644 index 000000000000..f9b84890d809 --- /dev/null +++ b/packages/kit/test/apps/options-2/vite.config.js @@ -0,0 +1,17 @@ +import * as path from 'path'; +import { sveltekit } from '@sveltejs/kit/experimental/vite'; + +/** @type {import('vite').UserConfig} */ +const config = { + plugins: [sveltekit()], + server: { + // TODO: required to support ipv6, remove on vite 3 + // https://github.com/vitejs/vite/issues/7075 + host: 'localhost', + fs: { + allow: [path.resolve('../../../src')] + } + } +}; + +export default config;