Use Bun with Astro
Bun is an all-in-one JavaScript runtime & toolkit. See Bun's documentation for more information.
:::cautionUsing Bun with Astro may reveal rough edges. Some integrations may not work as expected. Consult Bun's official documentation for working with Astro for details.
If you have any problems using Bun, please open an Issue on GitHub with Bun directly.:::
Prerequisites
- Bun installed locally on your machine. See the installation instructions in Bun's official documentation.
Create a new Astro project with Bun
Create a new Astro project with Bun using the following create-astro command:
bun create astro my-astro-project-using-bunInstall dependencies
If you skipped the “Install dependencies?” step during the CLI wizard, then be sure to install your dependencies before continuing.
bun installAdd Types
Bun publishes the @types/bun package, containing the runtime types for Bun.
Install @types/bun using the following command:
bun add -d @types/bunCLI installation flags
Using integrations
You can also use any of the official Astro integrations with the astro add command:
bun astro add reactUse a theme or starter template
You can start a new Astro project based on an official example or the main branch of any GitHub repository by passing a --template argument to the create astro command.
Run the following command in your terminal, substituting the official Astro starter template name, or the GitHub username and repository of the theme you want to use:
# create a new project with an official example
bun create astro@latest --template <example-name>
# create a new project based on a GitHub repository’s main branch
bun create astro@latest --template <github-username>/<github-repo>Develop and build
To run the development server, use following command:
bun run devBuild and preview your site
To build your site, use the following command:
bun run buildWhen the build is finished, run the appropriate preview command (e.g. bun run preview) in your terminal and you can view the built version of your site locally in the same browser preview window.
Testing
Bun ships with a fast, built-in, Jest-compatible test runner through the bun test command. You can also use any other testing tools for Astro.
Official Resources
Community Resources
Using Bun with Astro? Add your blog post or video to this page!
- Using Bun with Astro and Cloudflare Pages - blog post