W3cubDocs

/Astro

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!

Installing Bun

Use the following command to install Bun:

Terminal window

Create a new Astro project with Bun

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

Terminal window

Install your dependencies

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

Running the development server

To run the development server, use the following command:

Terminal window

Using Astro integrations

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

Terminal window

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

Building your site with Bun

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

Terminal window

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

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

Terminal window

More recipes

© 2021 Fred K. Schott
Licensed under the MIT License.
https://docs.astro.build/en/recipes/bun/