Skip to content

Commit

Permalink
[breaking] require vite.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 1, 2022
1 parent 3eb26e4 commit 2a2f798
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-trainers-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] require vite.config.js
10 changes: 2 additions & 8 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ function welcome({ port, host, https, open, base, loose, allow, cwd }) {
}

/**
* @param {import('types').ValidatedConfig} svelte_config
* @return {Promise<import('vite').UserConfig>}
*/
export async function get_vite_config(svelte_config) {
export async function get_vite_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
Expand All @@ -298,10 +297,5 @@ export async function get_vite_config(svelte_config) {
}
}

const { sveltekit } = await import('./vite/index.js');

// TODO: stop reading Vite config from SvelteKit config or move to CLI
const vite_config = await svelte_config.kit.vite();
vite_config.plugins = [...(vite_config.plugins || []), ...sveltekit()];
return vite_config;
throw new Error('vite.config.js is missing. See an example here: https://github.com/sveltejs/kit/blob/master/packages/create-svelte/templates/skeleton/vite.config.js');
}
22 changes: 5 additions & 17 deletions packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const options = object(
// TODO remove this for 1.0
ssr: error(
(keypath) =>
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle'`
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle`
),

// TODO remove this for 1.0
Expand All @@ -291,22 +291,10 @@ const options = object(
pollInterval: number(0)
}),

vite: validate(
() => ({}),
(input, keypath) => {
if (typeof input === 'object') {
const config = input;
input = () => config;
}

if (typeof input !== 'function') {
throw new Error(
`${keypath} must be a Vite config object (https://vitejs.dev/config) or a function that returns one`
);
}

return input;
}
// TODO remove this for 1.0
vite: error(
(keypath) =>
`${keypath} has been removed — use vite.config.js instead`
)
})
},
Expand Down

0 comments on commit 2a2f798

Please sign in to comment.