Skip to content

将 Bun 与 Astro 一起使用

Bun 是一款一体化 JavaScript 运行时和工具包。请参阅 Bun 的文档 了解更多信息。

¥Bun is an all-in-one JavaScript runtime & toolkit. See Bun’s documentation for more information.

¥Prerequisites

  • Bun 安装在本地计算机上。参见 Bun 官方文档中的 安装说明

使用 Bun 创建一个新的 Astro 项目

Section titled “使用 Bun 创建一个新的 Astro 项目”

¥Create a new Astro project with Bun

使用以下 create-astro 命令使用 Bun 创建一个新的 Astro 项目:

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

终端窗口
bun create astro my-astro-project-using-bun

¥Install dependencies

如果你在 CLI 向导中跳过了“安装依赖?”步骤,请务必在继续之前安装依赖。

¥If you skipped the “Install dependencies?” step during the CLI wizard, then be sure to install your dependencies before continuing.

终端窗口
bun install

¥Add Types

Bun 发布了 @types/bun 包,其中包含 Bun 的运行时类型。

¥Bun publishes the @types/bun package, containing the runtime types for Bun.

使用以下命令安装 @types/bun

¥Install @types/bun using the following command:

终端窗口
bun add -d @types/bun

¥CLI installation flags

¥Using integrations

你还可以使用任何官方 Astro 集成与 astro add 命令:

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

终端窗口
bun astro add react

¥Use a theme or starter template

你可以通过向 create astro 命令传递 --template 参数,基于 官方示例 或任何 GitHub 存储库的主分支启动一个新的 Astro 项目。

¥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.

在你的终端中运行以下命令,替换官方 Astro 入门模板名称或你要使用的主题的 GitHub 用户名和存储库:

¥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 dev

¥Build and preview your site

要构建你的网站,请使用以下命令:

¥To build your site, use the following command:

终端窗口
bun run build

构建完成后,在终端中运行相应的预览命令(例如 bun run preview),即可在同一个浏览器预览窗口中查看本地构建的网站版本。

¥When 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 通过 bun test 命令 提供了一个快速、内置且兼容 Jest 的测试运行器。你还可以使用任何其他 Astro 测试工具

¥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

将 Bun 与 Astro 一起使用?将你的博客文章或视频添加到此页面!

¥Using Bun with Astro? Add your blog post or video to this page!

Astro v5.16 中文网 - 粤ICP备13048890号