Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-rockets-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': minor
---

add experimental support for vite-8 beta
57 changes: 37 additions & 20 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ async function kit({ svelte_config }) {
/** @type {import('vite')} */
const vite = await import_peer('vite');

// @ts-ignore `vite.rolldownVersion` only exists in `rolldown-vite`
const isRolldown = !!vite.rolldownVersion;
// @ts-ignore `vite.rolldownVersion` only exists in `vite 8`
const is_rolldown = !!vite.rolldownVersion;

const { kit } = svelte_config;
const out = `${kit.outDir}/output`;
Expand Down Expand Up @@ -298,23 +298,6 @@ async function kit({ svelte_config }) {
`${kit.files.routes}/**/+*.{svelte,js,ts}`,
`!${kit.files.routes}/**/+*server.*`
],
esbuildOptions: {
plugins: [
{
name: 'vite-plugin-sveltekit-setup:optimize',
setup(build) {
if (!kit.experimental.remoteFunctions) return;

const filter = new RegExp(
`.remote(${kit.moduleExtensions.join('|')})$`.replaceAll('.', '\\.')
);

// treat .remote.js files as empty for the purposes of prebundling
build.onLoad({ filter }, () => ({ contents: '' }));
}
}
]
},
exclude: [
// Without this SvelteKit will be prebundled on the client, which means we end up with two versions of Redirect etc.
// Also see https://github.com/sveltejs/kit/issues/5952#issuecomment-1218844057
Expand Down Expand Up @@ -342,6 +325,40 @@ async function kit({ svelte_config }) {
}
};

if (kit.experimental.remoteFunctions) {
// treat .remote.js files as empty for the purposes of prebundling
// detects rolldown to avoid a warning message in vite 8 beta
const remote_id_filter = new RegExp(
`.remote(${kit.moduleExtensions.join('|')})$`.replaceAll('.', '\\.')
);
new_config.optimizeDeps ??= {}; // for some reason ts says this could be undefined even though it was set above
if (is_rolldown) {
// @ts-ignore
new_config.optimizeDeps.rolldownOptions ??= {};
// @ts-ignore
new_config.optimizeDeps.rolldownOptions.plugins ??= [];
// @ts-ignore
new_config.optimizeDeps.rolldownOptions.plugins.push({
name: 'vite-plugin-sveltekit-setup:optimize-remote-functions',
load: {
filter: { id: remote_id_filter },
handler() {
return '';
}
}
});
} else {
new_config.optimizeDeps.esbuildOptions ??= {};
new_config.optimizeDeps.esbuildOptions.plugins ??= [];
new_config.optimizeDeps.esbuildOptions.plugins.push({
name: 'vite-plugin-sveltekit-setup:optimize-remote-functions',
setup(build) {
build.onLoad({ filter: remote_id_filter }, () => ({ contents: '' }));
}
});
}
}

const define = {
__SVELTEKIT_APP_DIR__: s(kit.appDir),
__SVELTEKIT_EMBEDDED__: s(kit.embedded),
Expand Down Expand Up @@ -911,7 +928,7 @@ async function kit({ svelte_config }) {
preserveEntrySignatures: 'strict',
onwarn(warning, handler) {
if (
(isRolldown
(is_rolldown
? warning.code === 'IMPORT_IS_UNDEFINED'
: warning.code === 'MISSING_EXPORT') &&
warning.id === `${kit.outDir}/generated/client-optimized/app.js`
Expand Down
Loading