Hello from Bun!
Bun 1.0 less than an hour ago (at the time of publishing), and to celebrate this, I’ve migrated my blog’s build process to Bun! This details how I now publish my static Astro blog to Cloudflare Pages using Bun.
First, a warning…
Before attempting this yourself, be warned that I used some hacky workarounds to bypass some existing issues with Cloudflare Pages, and Bun. I don’t recommend this for important deployments yet.
Build an Astro site with Bun
Bun 1.0 supports Astro out the box. To start using it, make sure you have Bun installed and updated. Delete your existing package lockfile (package-lock.json
, pnpm-lock.yml
, yarn.lock
) and use Bun to install dependencies.
To build your site using Bun, set this as your build command.
Workaround for the sharp
package
For those using sharp
, it currently has an issue when installed with Bun, but there are two workarounds you can try.
-
Set
sharp
as a trusted dependency in yourpackage.json
. -
If the first workaround failed, prefix your
build
command with the following to installsharp
manually.
Run bun --bun run astro build
to test your site builds successfully.
Deploy to Cloudflare Pages
Cloudflare Pages has experimental support for Bun. I found a gist from a user in the Cloudflare Developers Discord which documents what you need to do to enable it.
In your Cloudflare dashboard, navigate to your project and add these two environment variables.
Commit and deploy!
If everything works locally, and your Cloudflare environment variables are set, you’re ready to deploy your site! My blog is still relatively small, and takes under a minute to build. However, now than Bun 1.0 is out, I’ll be looking at other repos to use as benchmarks, and test how far I can push Bun. If you want to stay up to date with all my planned Bun & Astro content, and all my other shenanigans, be sure to subscribe to my email list (or the RSS feed) and follow me on Twitter.