在 Astro 中使用 Bun
Bun 是一个 all-in-one 的 JavaScript 运行时和工具套件。可请参阅 Bun 的文档 获取更多信息。
在 Astro 中使用 Bun 可能会存在一些问题,例如某些集成可能无法正常工作。有关详细信息,请参阅 Bun 的官方文档中与 Astro 一同使用的内容。
如果你在使用 Bun 时遇到任何问题,请直接在 Bun 的 GitHub 仓库提交一个 Issue。
- 在你的机器上安装了 Bun。请参阅 Bun 官方文档的 安装说明。
使用 Bun 创建一个新的 Astro 项目
Section titled “使用 Bun 创建一个新的 Astro 项目”使用以下 create-astro 命令并通过 Bun 创建一个新的 Astro 项目:
bun create astro my-astro-project-using-bun如果你在 CLI 向导中跳过了 “Install dependencies?” 这一步,那么在继续之前一定要先安装你的依赖。
bun installBun 发布了含有 Bun 的运行时类型的 @types/bun 包。
使用以下命令安装 @types/bun:
bun add -d @types/bunCLI 安装标志
Section titled “CLI 安装标志”使用 Astro 集成
Section titled “使用 Astro 集成”你也可以通过 astro add 命令来使用任意 Astro 官方集成:
bun astro add react使用主题或入门模板
Section titled “使用主题或入门模板”你可以通过在 create astro 命令中传入 --template 参数,基于 官方示例 或任意 GitHub 仓库的主分支来创建一个新的 Astro 项目。
在终端中运行以下命令,将官方的 Astro 起始模板名称,或你想使用的主题的 GitHub 用户名和仓库替换进去:
# 使用官方示例创建一个新项目bun create astro@latest --template <example-name># 基于某个 GitHub 仓库的主分支创建一个新项目bun create astro@latest --template <github-username>/<github-repo>要运行开发服务器,请使用以下命令:
bun run dev构建并预览你的网站
Section titled “构建并预览你的网站”要构建你的网站,请使用以下命令:
bun run build构建完成后,在终端中运行相应的预览命令(例如 bun run preview),即可在同一浏览器预览窗口中本地查看网站的构建版本。
Bun 自带一个快速、内置且与 Jest 兼容的测试运行器,可通过 bun test 命令 使用。你也可以 为Astro 使用任何其他测试工具。
已经在 Astro 项目中使用 Bun?请在此页面添加你的博客文章或视频!
Recipes