0nepeop1e

Just a random developer.

avatar

@eslym/sveltekit-adapter-bun v2

by 0nepeop1e a month ago, updated a month ago

eslym/sveltekit-adapter-bun has officially launched its version 2! 🥳

New features

Ready for bun build --compile

With the v2 adapter, the final bundle is now fully optimized for bun build --compile, making the experience much smoother when compiling into a single-file executable.

// Generated assets index file
import file from 'bun';
import f_0 from "./client/favicon.svg" with { type: "file" };
export const assets = new Map(/* ... */);

The with { type: "file" } annotation allows Bun to embed asset files directly into the executable.

# Example usage:
bun --bun run build
bun build --compile build/index.js --outfile ./app
./app

Ready for using bun instead of rollup for the final build

SvelteKit requires a final build step to bundle the generated server into a ready-to-use package. While rollup has traditionally handled this step, the v2 adapter now offers a smoother alternative with bun.

// svelte.config.js
import adapter from '@eslym/sveltekit-adapter-bun';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  /* ... */
  kit: {
    adapter: adapter({
      /* ... */
      bundler: 'bun'//[!code ++]
    }),
  }
}
WARNING

While Bun.build provides several benefits, it still has some known issues. If you experience any problems with the final bundle, consider using rollup instead.

Breaking Changes ⚠️

Custom Hooks Removed

In previous versions, this adapter included custom lifecycle hooks: beforeServe, afterServe, and setupCLI. These hooks have been removed in the current version. Since SvelteKit restricted hook exports starting from version 2.10.0, implementing custom hooks is now nearly impossible.

However, SvelteKit now officially provides an init hook, which functions similarly to the removed beforeServe hook. If you require similar functionality, consider using the init hook instead.

CAC Removed

Earlier versions wrapped the server with cac to turn the final bundle into a CLI application, allowing users to add custom commands via the setupCLI hook. Since this hook has been removed, the cac package has also been removed to eliminate unnecessary code from the bundle.

Runtime configuration must now be configured exclusively through environment variables. If you didn’t use custom CLI setups, the process for launching the app remains unchanged.

© 2025 0nepeop1e, All Rights Reserved

Powered by SvelteKit