Use Bun with Astro

Bun is a runtime for JavaScript built for speed. See Bun’s documentation for more information.

Using Bun with Astro still is experimental. Some integrations may not work as expected. If you have any problems using Bun, please open an issue on GitHub!

Use the following command to install Bun:

Terminal window
curl -fsSL https://bun.sh/install | bash

Copied!

Create a new Astro project with Bun

Section titled Create a new Astro project with Bun

Create a new Astro project with Bun using the following create astro command:

Terminal window
bunx create-astro@latest my-astro-project-using-bun

Copied!

If you’re starting a new project using bunx create-astro, the CLI will automatically use Bun to install dependencies and you can skip this step.

Otherwise, you’ll need to install your dependencies with Bun:

Terminal window
bun install

Copied!

Running the development server

Section titled Running the development server

To run the development server, use the following command:

Terminal window
bun run dev

Copied!

You can also use any of the official Astro integrations with Bun and the astro add command:

Terminal window
bunx astro add react

Copied!

This will work exactly the same as if you were using NPM, but with the added benefit of using Bun’s blazing fast runtime.

To build and serve your site, Bun has familiar commands:

Terminal window
bun run build

Copied!

Bun’s build command will output your site to the dist/ directory.

Then, you can serve your site using the preview command:

Terminal window
bun preview

Copied!


More recipes