From 61db3b584ffc18bdd53edc3d7716b6b4643517ed Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 9 Dec 2022 06:42:46 +0800 Subject: [PATCH] [breaking] make `sveltekit()` return a promise (#7994) --- .changeset/fast-mails-run.md | 5 +++++ packages/kit/src/exports/vite/index.js | 29 +++++++++++++++++++------- packages/kit/types/ambient.d.ts | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 .changeset/fast-mails-run.md diff --git a/.changeset/fast-mails-run.md b/.changeset/fast-mails-run.md new file mode 100644 index 000000000000..929802c22d9b --- /dev/null +++ b/.changeset/fast-mails-run.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[breaking] make `sveltekit()` return a promise of array of Vite plugins diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 0b6dcbb79e4e..70cae19b5934 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -59,9 +59,25 @@ const enforced_config = { root: true }; -/** @return {import('vite').Plugin[]} */ -export function sveltekit() { - return [...svelte(), ...kit()]; +/** @return {Promise} */ +export async function sveltekit() { + const svelte_config = await load_config(); + + /** @type {import('@sveltejs/vite-plugin-svelte').Options} */ + const vite_plugin_svelte_options = { + configFile: false, + extensions: svelte_config.extensions, + preprocess: svelte_config.preprocess, + onwarn: svelte_config.onwarn, + compilerOptions: { + // @ts-expect-error SvelteKit requires hydratable true by default + hydratable: true, + ...svelte_config.compilerOptions + }, + ...svelte_config.vitePlugin + }; + + return [...svelte(vite_plugin_svelte_options), ...kit({ svelte_config })]; } /** @@ -74,12 +90,10 @@ export function sveltekit() { * - https://rollupjs.org/guide/en/#build-hooks * - https://rollupjs.org/guide/en/#output-generation-hooks * + * @param {{ svelte_config: import('types').ValidatedConfig }} options * @return {import('vite').Plugin[]} */ -function kit() { - /** @type {import('types').ValidatedConfig} */ - let svelte_config; - +function kit({ svelte_config }) { /** @type {import('vite').ResolvedConfig} */ let vite_config; @@ -193,7 +207,6 @@ function kit() { */ async config(config, config_env) { vite_config_env = config_env; - svelte_config = await load_config(); env = get_env(svelte_config.kit.env, vite_config_env.mode); diff --git a/packages/kit/types/ambient.d.ts b/packages/kit/types/ambient.d.ts index 940fec911bbe..9011f3d34d3f 100644 --- a/packages/kit/types/ambient.d.ts +++ b/packages/kit/types/ambient.d.ts @@ -433,5 +433,5 @@ declare module '@sveltejs/kit/vite' { /** * Returns the SvelteKit Vite plugins. */ - export function sveltekit(): Plugin[]; + export function sveltekit(): Promise; }