Skip to content

Commit

Permalink
[breaking] make sveltekit() return a promise (#7994)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Dec 8, 2022
1 parent 132dece commit 61db3b5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-mails-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] make `sveltekit()` return a promise of array of Vite plugins
29 changes: 21 additions & 8 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,25 @@ const enforced_config = {
root: true
};

/** @return {import('vite').Plugin[]} */
export function sveltekit() {
return [...svelte(), ...kit()];
/** @return {Promise<import('vite').Plugin[]>} */
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 })];
}

/**
Expand All @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,5 @@ declare module '@sveltejs/kit/vite' {
/**
* Returns the SvelteKit Vite plugins.
*/
export function sveltekit(): Plugin[];
export function sveltekit(): Promise<Plugin[]>;
}

0 comments on commit 61db3b5

Please sign in to comment.